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

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)

Related

Copy from FTP server to a network server with Windows cmd.exe

I want to make a batch file to copy files from an FTP server (external) to a network drive.
I am not sure which command to use.
That will be for a batch file on Windows 10
Many thanks.
Use Windows ftp.exe:
ftp -s:download.txt
Where the download.txt may look like:
open ftp.example.com
username
password
get /remote/path/file.txt \\localserver\share\path\file.txt
bye
Though Windows ftp.exe does not support passive mode FTP, what makes it useless nowadays in lot of scenarios due to ubiquitous firewalls and NATs.
If you face a problem with this, you will have to use a 3rd party FTP client (see How to use passive FTP mode in Windows command prompt?) or some more powerful scripting language than a batch file (e.g. PowerShell).

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.

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.

Run a script in remote UNIX using windows command prompt

I currently connect to my UNIX installed on my remote server using Secure CRT. I have a script(sh) on my UNIX which generates a file. I need to su(switch user) before executing the script.
I then ftp to this server(using ftp commands in command prompt on windows) and get the file generated by the above shell script.
However, I would like to automate this process and create a windows .bat file which would connect me to the UNIX server, su and run the required shell script and fetch the file.
I have found that I cannot run the shell script on UNIX using ftp. Could you please suggest me alternate ways to automate this?
Thanks
Thanks for your help guys :) I created a script on secure CRT and while running the application using the bat file, I'm calling this script using the CRT command line options

Resources