I'm trying to download a file from an FTP using a script:
Script.bat
ftp -s:DownloadFiles.ftp
DownloadFiles.ftp
open ftp_server
user
pass
ascii
prompt
lcd D:\LocalPath
mget "File.*.TXT_T;1"
When I run the Script.bat I get the following error:
550-Failed to open CV0:[user]File^^^.20171104_024043.TXT_T; for input
. 550 file not found
According to this link, the problem seems to be that the file name contains multiple dots and the mget command will not found the file. Updating the server might solve the problem but I can't do that.
Has anyone dealt with this before?
Related
I want to use a Batch file to upload files from a folder on my computer.
When I call the FTP Script to do the upload:
FTP -v -i -s:ftp.txt
or
FTP -v -i -s:c:\path\to\file\ftp.txt
Neither of those works, and instead
Error opening script file: ftp.txt
is returned.
Strange thing is, that the exact same script is being executed without problems on another computer.
Opening the batch file with admin-rights does not help. I'm running Windows 10.
Edit: The ftp.txt looks like this:
open ##host##
##user##
##password##
lcd c:\local\path\
cd path/on/server/
binary
mput "*.xxx"
disconnect
bye
Make a new, empty file with echo >ftp.test and try with that file.
If that gives you the same error, you'll need to look at your execution environment (look at set and the process owner of cmd.exe). It's also possible that the ftp command is being run as a user that doesn't have access to that file.
If you don't get an error then it's probably either a file-permissions or special-character issue with ftp.txt. Retyping the same content into a different file will get around those issues. Remember not to copy/paste because you could accidentally copy invisible special characters that you're trying to avoid.
I would like to add to this conversation since there have been a lot of views and no solution. I had the same response and it wasn't a permissions issue. It was also no the text file that was the issue because it never technically reached the text file. It was the path to the text file. The following for me didn't work. I had to put quotations around the path even though there were no spaces to confuse the command line.
What you tried:
FTP -v -i -s:c:\path\to\file\ftp.txt
What I tried and worked. (I didn't need to use -v, mine works without it)
FTP -i -s:"c:\path\to\file\ftp.txt"
Running the file acted normal for me. My issue was trying to run the batch file through Windows Task Manager. Somehow, this was causing it to lose the text file somehow. I hope this helps anyone else who reads this thread.
I had to put the .txt file path in the "Start In" section for it to work in Windows Task Manager. No problems since.
My problem appears when I try to download files with a batch file over the FTP.
OPEN 192.168.0.1
test
password
lcd Download-dir
cd /filedir
BINARY
get *.txt
Everything works well up to the moment he try to find the File. At that moment he call the
Error 550 File not Found.
When I try the same with
get Test.txt
It will work fine.
Every tutorial use the * as wildcard but why does it not work for me.
Thanks for help.
The get command in ftp.exe does not support wildcards.
You have to use the mget command:
mget *.txt
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.
There is a ftp command in my batch script :
FTP -n -s:D:\scripts\Test\get.ftp
Where get.ftp contains all ftp commands including "mget abc*".
Issue here is when file(s) of names starting with abc* is not available, mget is not failing. Also, if any other ftp command fails also, the script is not exiting with error status 1. i.e. "FTP -n -s:D:\scripts\Test\get.ftp" exiting without issues.
Not able to make the batch script fail when there is no file to pick up.
Need suggestion if someone has faced similar issue.
-Krishna
The mget command works by obtaining a remote folder listing and parsing the list for the wildcard pattern that you provide. As long as the listing can be obtained successfully,
it is not considered an error if your pattern did not match any of the files on the list.
Your batch script can be setup to compare the local folder listing before and after invoking the ftp command to check if a file was downloaded. You can also use a scripted ftp solution like kermit or ftp script to be able to have more control on error reporting.
How can I write a MS dos ftp batch file to:
download files from the server to my local pc
remove these files from the server after download
Edit:
So far I have...
Batch file:
ftp.exe -s:ftp.txt
FTP.txt:
open domain.com
usernamehere
passwordhere
cd /httpdocs/store/files
need get, list and delete commands here??
quit
The ftp.exe program can take a sort of script file as input (that example uploads a file, but I guess to get the idea), so you should probably be able to create a script for the commands that you need to carry out, and then have a batch file launch ftp.exe with the appropriate input.
From one of my cuestions in other post.
user-name
user-password
lcd c:\localfolder-where-download
cd remote-folder
mget .
mdelete \\remote-folder\ .
quit
1 & 2 line , your credentials
3 - line local folder where the ftp can download the content
4- line - remote folder if needed
5- line - get al content to your local folder
6- line - delete all content from your remote folder
7- line quit!
you can download ncftpput/ncftpget. With ncftpget, there's option to remove remote files after downloading.