Implicit TLS FTP connection using WinSCP or other command line FTP client in Windows - 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.

Related

how to sftp from file with -s pattern from windows client [duplicate]

This question already has answers here:
Secure FTP using Windows batch script
(3 answers)
Closed 4 years ago.
I have the following Windows script that connects to a regular FTP server and downloads files.
However, the files have since been moved to an SFTP server. How can I modify the following script so that it connects to this new secure ftp server? I really don't want to modify too much since it had been working correctly with the past FTP server.
The ftp client I'm using here is the one that's included with Windows.
I'm including the script:
I have a Windows task that runs the following: ftp -s:C:\files\FtpScript.txt
FtpScript.txt has the following contents:
open web.myserver.com 8021
username
password
lcd /Data/2014/0113
prompt
get /var/opt/Data1200.xml
get /var/opt/Data1300.xml
get /var/opt/Data1400xml
Windows command line FTP client does not support SFTP protocol.
You can switch to WinSCP:
replace your command line with:
winscp.com /script=C:\files\FtpScript.txt
replace your connection and authentication commands with:
open sftp://username:password#web.myserver.com/
the lcd can stay (though /Data/2014/0113 does not look like a local path)
in WinSCP the get needs a target path, use .\ to download to the local current working directory.
add the exit command
For details, see Secure FTP using Windows batch script or WinSCP guide for Converting Windows FTP script to WinSCP SFTP script
(I'm the author of WinSCP)

Downloading files with defined changed date time

Dears, could you please share your ideas how to download files from an FTP server to a local directory filtered by changed date.
So, I have a folder on the FTP server with files, but I need to move just those of them which have been changed yesterday (f.e.).
Thanks in advance for your reply.
open anymail.com
login
pass
!:--- FTP commands below here ---
lcd D:\Test
cd /home/my_folder
binary
mget *
disconnect
bye
You can hardly do this with the Windows built-in ftp.exe.
You would have to list the remote directory, redirect the listing to a file. Then parse the listing file to find the files you want. And then generate an ad-hoc download script. Quite a lot of work.
Use some more capable 3rd party Windows FTP command-line client.
For example with WinSCP scripting you can use a batch file (e.g. download_yesterdays.bat) like:
winscp.com /ini=nul /log=ftp.log /command ^
"open ftp://user:password#ftp.example.com/" ^
"cd /remote/path" ^
"lcd c:\local\path" ^
"get *>=yesterday<today" ^
"exit"
The >=yesterday selects files created since yesterday (inclusive). The <today excludes files created today. This syntax is supported since WinSCP 5.15.
In earlier versions of WinSCP, you can use %TIMESTAMP% syntax instead: >=%TIMESTAMP-1D#yyyy-mm-dd%<%TIMESTAMP#yyyy-mm-dd% (the TIMESTAMP-1D syntax is supported since WinSCP 5.9).
References:
WinSCP guide to Downloading the most recent file from FTP server
File masks with time-constraints
%TIMESTAMP% syntax
(I'm the author of WinSCP)

Can't transfer files using FTP script and batch on Windows

I have a folder with PDF files locally on hard disk and I want to upload files from this folder to an FTP server.
So I created a batch file that should upload PDF files to the FTP server. Everything seems to work fine and the console window displays File successfully transferred, but actually no file really uploaded.
The FTP script content:
open
000.000.000.000 -- not the real ftp server ip lol
bla#nirlatpro.com
PASSWORD
mput c:\Batch\*.pdf
quit
Command window with output on running this script:
It looks like it works, but no file is actually uploaded.
What is even more strange is if I connect to FTP using GUI application and drag the files, it does work and all the files are uploaded to the server.
summary:
- It's works fine if i'm using windows explore and dragg the files.
- It's not uploading the files if i'm using cmd commands or batch script with ftp file, even if the console window displays 'File successfully transferred'
it was a permissions problem
apparently the ftp server does not allowing to copy files in to the root directory /
console window display it "Current restricted directory is / "
I too Faced a similar problem downloading a file from ftp through command line, But every time my request was rejected and my connection was not established.
After a thorough research i found the t i need to do settings in the IIS for ftp.
Steps:
1) Set your IIS Server on.
a:Goto control panel-->Programs&Features-->Turn windows Features on or off-->Internet Information Services.
b: Expand the Internet Information services-->Check FTP services-->Expand FTP Server-->FTP Service (Check it)-->press OK.
2)Open IIS Manager(win+r-->inetmgr)
a: Select FTP authentication-->Enable Anonymous Authentication or Base Authentication (as per your requirement).
b: Select FTP Authorization-->Select All users, give permissions (read or write or both) & press ok.
c) Open FTP Directory Browsing select MS-DOS for windows Server or Unix for Unix server.
3) Finally goto Services.msc(win+r-->'services.msc')-->MicrosoftFTPServices-->restart.
Now goto your command prompt and write your respective code for ftp it will work.

Download files from Unix server using WinSCP with get command

I have program in Unix that generates files 8 files at 8:30 pm everyday.
I need to download the files into my Windows machine after the files are generated using WinSCP.
I can drag and drop those but its time consuming, I need to automate this process.
I cannot use .Net assembly to download those.
I have tried to use the get command, but its throwing error: Not an SCCS file.
Let me know how can I solve this.
--Thanks
To automate a task using WinSCP, use its scripting interface from a batch file (e.g. download.bat).
I assume you want to use SFTP, as you are connecting to a *nix server.
The simplest download batch file is like:
winscp.com /log=c:\path\to\log\winscp.log /command ^
"open sftp://username:password#example.com/ -hostkey=""xxx""" ^
"get /path/to/file.ext c:\path\to\download\to\" ^
"exit"
Replace the username, password and example.com with the actual connection details. Get the value of -hostkey switch from your GUI session. Use real paths.
Though it's easier to have WinSCP generate the batch file for you.
For details see a guide to automating file transfers from SFTP server using WinSCP.
Once you have the batch file working, schedule the the batch file execution using Windows scheduler.
See a guide to scheduling file transfers from SFTP server.

How to change remote file permission via FTPClient

I need to handle remote file on a ftp server via commons-net-1.4.1.jar,class org.apache.commons.net.ftp.FTPClient.It's seems that no api available to change a file's permission,just like unix shell command chmod.
Anyone know any solution to resolve this issue?
FTP doesn't have a command for such operations, since the operation is platform-specific. If your library supports this, you can try using SITE command and pass the command line as a parameter of SITE command. Some servers support this trick to run shell commands.

Resources