Upload files using a batch file not sending ftp commands? - batch-file

The command I am sending is:
ftp -s:ftp.txt
Here are the contents
open host.com
user
pass
lcd .
cd ./public_html/path/to/dumps
binary
mput "omega.txt2"
mput "wo.txt2"
When I run this, it logs in just fine but then stops. How can I make it run the mput commands also once it connects?

ftp displays a confirmation prompt to start uploading and waits for your input.
Use -i command line switch to disable prompting:
ftp -i -s:ftp.txt

Try to debug your script by connecting without it and then run each ftp command by typing in cmd:
ftp ftp.host.com
user
...
mput "wo.txt2"
This might help:
Ftp
Ftp subcommands

Related

FTP script failing [duplicate]

This question already has answers here:
How to ftp with a batch file?
(10 answers)
Closed 4 years ago.
I am trying to create a script which copies the contents of one directory to an FTP location but every example I have tried to work with has failed. I need this to target a folder within the FTP site can anyone point me in the right direction.
Thank you
Batch file is below.
#ftp -i -s:"%~f0"&GOTO:EOF
open 0.0.0.0
name#address.com
Pa55word
!:--- FTP commands below here ---
lcd c:\program files\system\location
cd storage
binary
mput "*.*"
disconnect
bye
Once FTP is open you are no longer at a command prompt. You are inside FTP. You need to use your batch file to write the ftp script,FTPInstructions.ftp in the following example. Then open ftp, telling it to run the script.
When you invoke the ftp.exe program to run the ftp script from the batch file you can redirect the ftp.exe console output to a log file and examine that log file for errors. You'll need to redirect both stdout and stderr. Something like this:
echo open 0.0.0.0>FTPInstructions.ftp
echo user UserName>>FTPInstructions.ftp
echo Password>>FTPInstructions.ftp
echo something>>FTPInstructions.ftp
echo something else>>FTPInstructions.ftp
.
.
echo bye>>FTPInstructions.ftp
ftp.exe -n -s:FTPInstructions.ftp>FTPSession.log 2>&1
You can then use FIND or FINDSTR in the batch file to locate any error messages output by ftp.exe in the FTPSession.log file.

Execute sftp commands on remote server using batch file and PuTTY

I have to transfer a file from one server to another. I log in to the first one with PuTTY and then type this:
sftp -v -oIdentityFile=path username#host
cd path
put file
Everything works perfectly! Now I'm trying to do it with a batch file. In the .bat I have:
putty.exe -ssh host1 -l username1 -pw password1 -m script.txt
In the script.txt file:
sftp -v -oIdentityFile=path username2#host2
cd path
put file
exit
It connects to the server number two but then it stops. The prefix sftp> does not appear and it does not read the following lines. Do you have any suggestion?
The remote shell takes the commands and executes them one by one. So it executes the sftp, waits for it to exit (what it never does) and only then it would execute the cd command (but in shell, not in the sftp), the put (failing as that's not a shell command), etc.
If your intention was to simulate typing the commands as on a terminal, use Plink and input redirection.
The Plink (PuTTY command-line connection tool) is a tool from PuTTY package that works like PuTTY, but it is a console, not GUI, application. As such it can use input/output redirection. And anyway, the Plink is the tool to automate tasks, not PuTTY.
plink.exe -ssh host1 -l username1 -pw password1 < script.txt
For more details, see How to type commands in PuTTY by creating batch file? on Super User.

FTP Glob won't work

I have a problem with ftp via command line.
This is how I run the ftp file:
ftp -i -s:backup.ftp
pause
And this is my ftp file:
open HOST
USER
PASS
mget *.json
disconnect
quit
I am getting an error: no such file or directory. However if I change the * by a specific filename, it will work. As you can see, I didn't turn globbing off.
Also, when I connect to another ftp server, globbing does work. It seems like this ftp server blocks globbing or something. Anyone an idea??

Encountering erros when trying to automate PSFTP command using a .bat file

In looking at other posts, "Batch file for PuTTY/PSFTP file transfer automation", regarding automating the PSFTP command in a .bat file so that I can setup a Windows Scheduled Task, I tried the following but got the error below:
In the .bat file that I'm executing I have the following lines:
#echo off
cd "c:\PuTTY"
psftp 999.99.999.999 -l XXXXXIO -i testGSX.ppk -b DownloadDiscoverReports.txt
In the DownloadDiscoverReports.txt file I have the following lines:
lcd c:\Reports\GSXDLFILES\ALLRPTS
cd /DSCVROUT/ALLRPTS/
mget *ALLRPTS%POLLABLE*
lcd c:\Reports\GSXDLFILES\XMIT81
cd /DSCVROUT/XMIT81/
mget *XMIT81%POLLABLE*
The error I'm getting when I execute the .bat file from my C:\ is:
C:\>gsx_dl.bat
psftp: no hostname specified; use "open host.name" to connect
New local directory is c:\Reports\GSXDLFILES\ALLRPTS
psftp: not connected to a host; use "open host.name"
C:\PuTTY>
Any suggestions/direction on how to fix this issue would be appreciated. Thank you.
This issue has been resolved. PuTTY support responded to my issue and I entered a -v switch to my command and found that my KEY had expired and that was the issue.
Thanks anyway.

Batch file uploading entire folder to FTP

I am trying to upload entire a folder to ftp but it just uploads one file, what could be the problem?
Open Run window → cmd → ftp -s:C:\ftpfile.bat
This is my batch code code:
open FTP address
USERNAME
PASSWORD
bin
mput C:\user\*
bye
Thanks from now.
Have you tried to use prompt before mput in order to deactivate interactive mode?
open FTP address
USERNAME
PASSWORD
prompt
bin
mput C:\user\*
bye

Resources