1

I have this batch file which will be able to send files to my FTP. It logs in and everything but connects via the wrong port. Is there a way I can make this connect via port 22? This FTP is with 000webhost

@echo off
CD %userprofile%/desktop
echo user MyUsername> ftpcmd.dat
echo PASSWORDHERE>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat files.000webhost.com
del ftpcmd.dat
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
CyberhiT
  • 33
  • 1
  • 1
  • 7

2 Answers2

0

For an answer to your literal question, see:
Cannot connect to non standard port number with Windows command-line ftp.


Though, the port 22 is for SSH/SFTP. That has nothing to do with FTP, so you cannot use command-line ftp.

There's no built-in SFTP client in Windows. You have to use some 3rd party SFTP client.

For that, see Secure FTP using Windows batch script.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
-1

There is a alternative way for this. The ftp command has a subcommand open, and the open subcommand support specific port, Click here. So you can put the subcommand open in your ftpcmd.dat file and open connect to your ftp server with a specific port via this subcommand.

For example, I did a test on my site, open ftp connect to a ftp server 172.18.128.122 with port 21, it works.

C:\>ftp -d -v -s:test.txt 127.0.0.1   #note, it is not ftp server ip here.
ftp> open 172.18.128.122 21           
Name(172.18.128.122:(none)):
---> USER test
---> PASS test
ftp> put aaa.txt
---> PORT 172,18,128,121,218,69
---> STOR aaa.txt
ftp> quit
---> QUIT

And my test.txt file is like below:

open 172.18.128.122 21
test
test
put aaa.txt
quit

So I think your bat file can be like below:

@echo off
CD %userprofile%/desktop
echo open files.000webhost.com 22> ftpcmd.dat
echo user MyUsername>> ftpcmd.dat
echo PASSWORDHERE>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat 127.0.0.1
del ftpcmd.dat

Hope it help, FYI.