cmd upload (windows server 2012) - ftp

I have command in ftp.txt
open ftp.web.cz
jmeno
heslo
prompt
mput C:\upload\*
quit
This command call in ftp. bat (ftp -s:C:\ftp.txt ), but show error - Error opening local file.Can I help me? Thank you

Use lcd to change local working directory and cd to change remote working directory. Consider whether specify ascii and / or binary transfer type.
open ftp.web.cz
jmeno
heslo
prompt
[cd "/destinationfolder"]
lcd "C:\upload"
mput *.*
quit

Related

How to execute further batch file commands after running "ftp" commands contains in the batch file itself

I have a .bat document where I do some operations with FTP. I want to end the FTP connection and get to finish with the terminal on the desired directory.
I'm trying this, but when it gets to quit, it stops.
cd %USERPROFILE%\Foilder\project\angular
call ng build
#FTP -i -s:"%~f0"&GOTO:EOF
open connection
user
password
cd httpdocs/project
mdelete *.woff
quit
cd %USERPROFILE%\Foilder\Subfolder
It gives me this message right after doing the quit and never runs the next line.
221 Goodbye.
Ideal scenario, run this last cd command and have the terminal ready on the folder that I want to run it. Thing is that I have to do some uploads to two different FTP servers and it would be great to have the console finishing in the folder where I run "dev.bat" to get it to work
Is it possible to do this?
Your script uses a known hack that allows you to specify ftp commands directly in the batch file.
The %~f0 is replaced with the path to the batch file itself. So the ftp -s:%~f0 runs ftp and tells it to use the batch file itself as ftp script file. You have probably noticed that it results in couple of errors, as ftp fails on the first few lines of the batch file, which are not valid ftp commands (the cd ..., call ... and ftp ...).
Equivalently, the batch file would try to run all commands after ftp ... once ftp finishes, also failing, as those are not valid batch file commands. To avoid that, the hack uses GOTO:EOF to skip the rest of the batch file (EOF=eof of the file).
While you actually want to execute some commands after the ftp. At least the cd command. So do not skip the rest of the batch file. Skip only the ftp commands:
ftp -i -s:"%~f0"&goto AFTER_FTP
(ftp commands)
quit
:AFTER_FTP
cd %USERPROFILE%\Foilder\Subfolder
Note the # before ftp. That (and the GOTO:EOF) are clear signs, that the script you based your batch file on, was designed to start with ftp on the very first line and contain nothing else, but the ftp commands. You have deviated from that.
Alternatively, use some more capable FTP client that allows specifying the commands on its command-line without hacks.
For example with my WinSCP FTP client, you can do:
cd %USERPROFILE%\Foilder\project\angular
call ng build
winscp.com /ini=nul /command ^
"open ftp://user:password#connection/" ^
"cd httpdocs/project" ^
"rm *.woff" ^
"exit"
cd %USERPROFILE%\Foilder\Subfolder
There's a guide for converting Windows ftp script to WinSCP script.

mget in batch script does not work

i'd like to create a batch script which logs on a ftp-server and copies some files to a remote folder. but my script does not work. mget runs into a timeout (has to be terminated manually).
i'm starting ftp connection with ftp.bat:
ftp.exe -s:getdata.bat
getdata.bat:
OPEN host-ip
user
password
lcd "C:\tmp"
cd config
mget C1000.xml
close
starting, logging in and changing the directory works but getting the file doesn't work. nothing happens until i end the script manually. any hints?
regards,
michael
mget prompts for user confirmation for each file it finds, even when you only specify one specific file.
To get around this, you can either use get if you know the file name, or you can use prompt to disable the interactive prompt before you use mget.
OPEN host-ip
user
password
lcd "C:\tmp"
cd config
prompt
mget C1000.xml
close

How to delete local computer files in the ftp session with a file. scr?

I have a .bat file (test.bat) :
ftp -s:Test_DOWN.scr
pause
I have a .scr file (Test_DOWN.scr) :
open ftp01.citobi.be
USERNAME
PASSWORD
prompt n
mput *.csv
quit
cd C:\...
del *.csv
The problem is that I want to remove files in my directory C:... but when I execute test.bat, it doesn't execute the last two lines.
I want to know if it is possible to run these two lines in the same script after ftp commands?
ps : When I launch prompt command from start --> run --> cmd and I connect to ftp. The quit ftp command works well, I pass the ftp session to host session. But with the .bat file, after quitcommand, it's over..
I solved the problem...
I used ! ftp command (escape to the shell).
!del *.csv
And it works well.

Implicit TLS FTP connection using WinSCP or other command line FTP client in Windows

I need to connect to an FTP secured with implicit TLS, username and password from the command line so that I can create a batch later on. I am using WinSCP since it's the most popular (I think) or the one that I can use to achieve this according to extensive googling. I'm not an expert but reading the documentation I have this so far with unsuccessful connection from command prompt:
winscp> open username:password#host:port -implicit -certificate="aa:aa:aa:aa..."
Once connected I need to extract everything there to a folder \hostname\folder or c:\folder then delete the files on the ftp (more or less like cut)
Thanks to Martin Prikryl correction I was able to connect, here is what I did:
Created a text file with the winscp.com commands "connection.txt":
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect with username and password
open ftp://username:password#host:port -implicit -certificate="aa:aa:aa:aa...."
# Change local directory
lcd C:\local_working_folder
# Force binary mode transfer
option transfer binary
# Download missing files to local directory from remote
synchronize local
# Delete all remote files
rm *
# Disconnect
close
# Exit WinSCP
exit
Now from command prompt or in a batch file you just call winscp.exe from where it is installed. If from installation media it should be C:\Program Files\WinSCP\WinSCP.exe of if extracted from a .zip portable version point to the folder where you extracted the file:
C:\WinSCP\WinSCP.exe /console /script="connection.txt" /log="conn.log"
Then just schedule the batch to automate the process.
Your syntax is almost correct. You are missing only the protocol prefix ftp:// (note that WinSCP defaults to the SFTP protocol).
open ftp://username:password#host:port -implicit -certificate="aa:aa:aa:aa..."
For details see:
https://winscp.net/eng/docs/session_url
https://winscp.net/eng/docs/scriptcommand_open
If that does not help, you need to share with us a script log file or at least an error message.

Windows command-line ftp put/upload files older than 1 minute

I have the following batch file:
open <ip>
username
password
bin
lcd C:\FTP_OUT\
prompt
mput *.PDF
ascii
mput *.XML
bye
How do I change it to upload only files older than 1 minute to the FTP server?
The Windows ftp.exe does not support any kind of a file selection based on a file timestamp.
All you can do is to generate a temporary upload script with an explicit list of files to upload. You can use a PowerShell script to generate the temporary script (implementing in a pure batch file would be very difficult).
A way easier solution is to use an FTP client that supports selecting files based on file timestamp.
For example with WinSCP FTP/SFTP client you can use the following batch file:
#echo off
winscp.com /log=upload.log /command ^
"open ftp://username:password#example.com/" ^
"lcd C:\FTP_OUT" ^
"put *.PDF<1N" ^
"put -transfer=ascii *.XML<1N" ^
"exit"
The <1N in the files mask is a time-constraint that selects files created or modified more than one minute ago only.
See also the guide for converting Windows ftp.exe scripts to WinSCP scripts.
(I'm the author of WinSCP)

Resources