How to convert Windows FTP script to WinSCP? - ftp

I need to use WinSCP in my legacy vb6 code. I always used my script like this:
open ftp.myserver.com
myusername
mypassword
passive on
cd myfolder\
ascii
put C:\temp\test.xml test.xml
close
quit
Similar script (with little change) always worked for sslftp, psftp, etc.
Now I need to create script to make this WinSCP work but it keeps throwing "host not found error". I'm not even trying the script. I'm trying it on the command window.
winscp> open ftp.myserver.com
Searching for host...
Network error: Connection timed out.
same ftp works on regular command line ftp:
ftp> open ftp.myserver.com
Connected to myserver.
220 Gene6 FTP Server v3.10.0
User (...): myuser
331 Password required for myuser
Password:
230 User manager logged in.
How do I run WinSCP? The documentation doesn't show any such example.

WinSCP defaults to the SFTP protocol on the port 22. If you want to use the FTP, you need to specify that explicitly.
Also username and password come in session URL as part of the open command, not on separate lines. The passive mode is specified using the -passive=on switch.
open ftp://myusername:mypassword#ftp.myserver.com -passive=on
The ascii mode is specified using the -transfer=ascii switch of the put command (though the separate ascii command is also understood for compatibility):
put -transfer=ascii C:\temp\test.xml test.xml
It's the exit, not the quit.
See the complete guide for converting Windows FTP script to WinSCP.
You should also read the guide to automating file transfers to FTP server.

Related

Copying files to an FTP server on AWC EC2 Windows server fails with "Unable to build data connection: The connection waiting time has expired"

We switched to to the AWS cloud with our local build machine. Now there is a batch file, which should upload a file via ftp. This worked fine locally, but not over the EC2 AWS machine.
C:\Programme\WinRAR\winrar a -afzip -IBCK -ep "Tool_%date:~-2%%date:~-7,2%%date:~-10,2%.zip" master
#echo Upload...
#echo open URL>ftp.txt
#echo USERNAME>>ftp.txt
#echo PASSWORD>>ftp.txt
#echo binary>>ftp.txt
#echo put TOOL_%date:~-2%%date:~-7,2%%date:~-10,2%.zip "/downloads/Tool%.zip">>ftp.txt
#echo quit>>ftp.txt
ftp -s:ftp.txt >out.txt
That does not work... I opened in the security groups settings: Inbound and Outbound ports 20-21, 1024-1048. It uploads the zip archive with 0 bytes.
The log file says:
ftp> open URL
Connection to URL was established.
220 FTP on server ready
200 UTF8 set to on
User (URL: (noone)):
331 Password required for USERNAME
230 user USERNAMElogged in
ftp> binary
200 type set to I
ftp> put Tool_180418.zip "/downloads/Tool_180418.zip"
200 PORT command successful
425 Unable to build data connection: The connection waiting time has expired
ftp> quit
221 goodbye.
Windows command-line ftp client supports FTP active mode only. To be able to use it, you have to open ports on your local Windows firewall. (And maybe outbound ports on the AWS instance.)
See my article on network configuration for FTP active and passive connection modes.
You better use another FTP client that supports an FTP passive mode, for which you seem to have everything set up correctly already.
For example, with WinSCP scripting, you can use a batch file like:
winscp.com /log=upload.log /command ^
"open ftp://username:password#ftp.example.com/" ^
"put TOOL_%%TIMESTAMP#ddmmyy%%.zip /downloads/*" ^
"exit"
There's even a guide for converting Windows ftp.exe script to WinSCP script.
WinSCP has also a built-in %TIMESTAMP% syntax, what the example above takes advantage of. It is more reliable than %date% and easier to use.
(I'm the author of WinSCP)
Unless you have specifically configured your FTP server to use the range 1024-1048 for file transfer, it will most likely be attempting to use ports in the range 1024-65535.
You need to either configure your FTP server so that it permits connections only in the permitted 24 port range, or else open your security group to the entire range.
Edit: have you seen this very useful answer ?

sftp from batch file

I need some files from unix server. So, I am making sftp connection with password from my windows 7 machine to unix server. but, now i want to include all these commands in batch file.
So, I need help on how should make sftp connection from batch file (basically, how to pass password to sftp prompt from batch file)?
Commands I am using:
> C:\Users\e578589>sftp
> server : TSEDCLVSAPPD116.svr.us.jpmchase.net
> user name : a_avatar
>a_avatar's Password:
/home/a_avatar>cd /data/ailsa/archive/open-loans-txns-to-bancs
/dev2/data/ailsa/archive/open-loans-txns-to-bancs> get {$FILENAME}
May be the following solution you can think for your unix/linus server as well.
Secure FTP using Windows batch script
How about PSCP - PuTTY Download Page? It is easy to use in batch script.
pscp.exe -P PORT -pw PASSWORD USERNAME#IPADDRESS:SOURCE_PATH DEST_PATH
Perhaps you can use PSFTP (PuTTY Download Page) in the same way.

mget prompt override

I am using ftp in the command line (terminal) to transfer multiple data files from a remote server to my local computer. There are multiple files (~40) in the directory and I would like to transfer them all without having to answer yes in the prompt for each file. I tried mget * but this only transferred the first file and then a prompt popped up for the second file.
Issue a prompt command first to turn interactive prompting off.
Alternatively, if you have control over the way the ftp command is called, use the command line option, as suggested by #reg-edit:
ftp [-i | --no-prompt] [OPTIONS] [HOST [PORT]]
As an alternative to issuing a prompt command ahead of your other commands, you may invoke ftp with the -i switch.
When you already started ftp you can issue the prompt command to toggle between getting prompted and not getting prompted. So this should do the trick:
> ftp <some server>
ftp> prompt
Interactive mode OFF .
ftp> mget *

how to log-in and execute ftp commands in native windows telnet client program using only one command

What I want to do is issuing one command that contains ftp commands that I want to execute. I want my command to contatin username, password and commands.
I only can use windows native ftp client program, and it seems it does not provide any help regarding this. What should I do?
did you read 'ftp /?' for example
Ftp -s:YouFileWithFtpCommands

Can we login to putty with FTP details

I tried to login with putty to the Server with FTP details Hostname, Username and Password. But it says Access Denied when i entered the Paassword.
For my another Website i entered my hostname and click open in putty, it shows "Network Error: Connection timeout".
But the 2 sites can be opened in FTP client like Smart FTP. To access through putty shall i need any permission or what else may be the problem.
Where i can find Putty Details i.e., Username and Password to login to putty in SSL. I need to execute MYsql insttruction, do File transfer etc., Please show me link to learn some commands.
If you want to use Putty to login to an FTP server you need to do it manually. You need to set a RAW connection to port 21. Once connected you need to send USER, followed by username, and PASS followed by the password.
You can find more info on RFC959 http://www.faqs.org/rfcs/rfc959.html
If you want to try another ftp software, give a shot to WinSCP.
Putty is an SSH/Telnet client not an FTP client - different protocol, different TCP port. FTP is typically exposed since it's less risk - SSH can be much more dangerous and I would suspect blocked if you're seeing a connection timeout message.
Make sure to create a folder called billing and place all the putty exe's and batch files.
echo off
echo Starting PSFTP and Logging Into FTPSITE.ORG
psftp.exe username#FTP.org -pw "PASSWORD" -b "C:\BILLING\SITE.CMD"
echo %d%%t%
move /y "C:\Interface\Charges\BILLING.EXP" "C:\Interface\Charges\Sent\BILLING%d%%t%.EXP"
echo Done Uploading Billing Results and Moving Files
exit

Resources