Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

DOS + FTP

SOLVED
Go to solution
Piotr Kirklewski
Super Advisor

DOS + FTP

Hi there
Does anyone know how to write a script which will connect to an FTP server automatically to put a file (backup)?
I was trying ftp user1@xxx.com but it didn't work.
Regards
Peter
Jesus is the King
7 REPLIES
Eric SAUBIGNAC
Honored Contributor
Solution

Re: DOS + FTP

Bonsoir,

You can try this way :

ftp -in -s FileName xxx.com

In FileName you place all ftp commands you need. For example :

user foo password
cd Target
binary
put File

Eric
Eric SAUBIGNAC
Honored Contributor

Re: DOS + FTP

Oups ... forgot ":" :-(

ftp -in -s:FileName xxx.com
Piotr Kirklewski
Super Advisor

Re: DOS + FTP

COMMAND:
C:\>ftp -in -s:ftp.bat myhost.com

BATCH FILE:
user itsme itsmypsswd
cd C:/
binary
put file.txt

RESULT:

C:\>binary
'binary' is not recognized as an internal or external command,
operable program or batch file.

C:\>put file.txt
'put' is not recognized as an internal or external command,
operable program or batch file.
Jesus is the King
James R. Ferguson
Acclaimed Contributor

Re: DOS + FTP

Hi:

I would suggest that you not implement your script with a login/password in the script itself, but rather use the '.netrc' file if you _must_ use FTP.

http://forums13.itrc.hp.com/service/forums/questionanswer.do?admit=109447627+1233077838233+28353475&threadId=231288

Better yet, use SFTP (Secure FTP) and public keys.

# cat .mysftp
HOST=$1
FILE=$2
sftp -b - <lcd /tmp
cd /tmp
put -P ${FILE} ${FILE}.backup
EOF
RC=$?
print -u2 "\nSFTP returned ${RC}"
exit

Regards!

...JRF...
Eric SAUBIGNAC
Honored Contributor

Re: DOS + FTP

If you have security issue, follow JRF solution.

But anyway, I would like to understand what is wrong with my post. Here is a little example from a Windows XP workstation :

C:\TEMP>cat CMDFILE
user anonymous me@hp.com
dir superseded_patches
cd superseded_patches
lcd C:\temp
binary
get catalog
bye


C:\TEMP>ftp -in -s:CMDFILE ftp.itrc.hp.com
Connecté à ftp.itrc.hp.com.
220-
220-Welcome to the IT Resource Center ftp server
220-------------------------------------------------------
220-
220-You are user 9, and there is a limit of 2000 simultaneous accesses.
220-
220-Log in as user "anonymous" (using your e-mail address as your password)
220-to retrieve available patches for HP-UX, OpenVMS, True64, MPE/iX, and
220-other platforms.
220-
220-If you are a user of other HP ITRC services, log in with your
220-HP ITRC User ID and password to retrieve your files.
220-
220-
220 g1u1296 FTP server (HP ASL ftpd, version(434)) ready.
ftp> user anonymous me@hp.com
331 Guest login ok, send your complete e-mail address as password.
230 Guest login ok, access restrictions apply.
ftp> dir superseded_patches
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 2302
drwxr-xr-x 7 21164 12753 1024 Jul 2 2003 .
drwxr-xr-x 21 2 2 1024 Oct 29 21:33 ..
-rw-r--r-- 1 21164 12753 1174127 May 15 2002 catalog
drwxr-xr-x 3 21164 12753 96 Mar 30 2006 firmware_patches
drwxr-xr-x 4 21164 12753 96 Jan 26 01:11 hp-ux_patches
drwxr-xr-x 6 21164 12753 1024 Dec 4 09:51 mpe-ix_patches
drwxr-xr-x 32 21164 12753 1024 Jan 25 05:57 mv_patches
drwxr-xr-x 2 21164 12753 96 Jul 2 2003 tru64_patches
226 Transfer complete.
ftp : 568 octets reçus en 0,03 secondes à 18,32 Ko/sec.
ftp> cd superseded_patches
250 CWD command successful.
ftp> lcd C:\temp
Dossier local maintenant C:\Temp.
ftp> binary
200 Type set to I.
ftp> get catalog
200 PORT command successful.
150 Opening BINARY mode data connection for catalog (1174127 bytes).
226 Transfer complete.
ftp : 1174127 octets reçus en 13,36 secondes à 87,88 Ko/sec.
ftp> bye
221 Goodbye.


As you can see, it works well. When you said "DOS" in the title of your thread, I have assumed "a cmd box from windows". On which version are you working from ?
Piotr Kirklewski
Super Advisor

Re: DOS + FTP

Hi

How to exclude one directory: /mount
from this backup?

find . -depth -print | cpio -ocv | gzip > /backup/backup.cgz
Jesus is the King
Piotr Kirklewski
Super Advisor

Re: DOS + FTP

That should be a next thread thou.

Jesus is the King