Reputation: 18645
I have a text file on one computer that I want to send to a folder on a ftp site. Can someone please show me a batch file code that will login to the FTP site with the username and password, and copy the text file.
Thanks for your help.
Upvotes: 2
Views: 28562
Reputation: 881403
If you mean batch as in Windows batch, you can do that with the following script tst.cmd
:
@ftp -n -stst.ftp myTargetMachine.com
(replacing myTargetMachine.com
with the name of your actual FTP server) and the following FTP command file tst.ftp
:
user myUser myPassword
dir
bye
Obviously, you should replace the myUser
and myPassword
with your actual username and password, and also dir
command with whatever you really want to do, such as:
put localfile.txt /fullpath/remotefile.txt
If you're talking about a UNIX-like environment, the script would be:
#!/bin/bash
ftp -n myTargetMachine.com <<EOF
user myUser myPassword
dir
bye
EOF
Same deal with the FTP server name, user ID and password, of course.
And, in response to your comment:
Yes, I am talking about from a Windows environment. So for arguments sake, let's say the text file is C:\textfile.txt and I need to copy it to the FTP site in the folder called BACKUPS.
You would use a script like the following transfer.cmd
:
@setlocal enableextensions enabledelayedexpansion
@echo off
c:
cd \
ftp -n -stransfer.ftp myTargetMachine.com
endlocal
and transfer.ftp
:
user myUser myPassword
put textfile.txt /backups/textfile.txt
bye
If you wanted the Windows version as a single file, you could use something like:
@echo off
echo user myUser myPassword>tst.ftp
echo dir>>tst.ftp
echo bye>>tst.ftp
ftp -n -s:tst.ftp myTargetMachine.com
del /q tst.ftp
which temporarily creates tst.ftp
and then deletes it when it's finished.
Upvotes: 10
Reputation: 61016
Command:
ftp -n -sScriptName HostName
And in the Script:
[User_id]
[ftp_password]
ascii
put myfilehere.html /remotedir/remotename.txt
quit
Upvotes: 1