views:

48

answers:

3

I am trying to connect to a remote servre via FTP in my VB 6.0 application.

I tried connecting to remote server using Inet but it gave status unknown error (code:120089). So I am trying to do this by batch file. I created a batch file as below:-

open 192.168.1.3 22  
root  
!@#%RedHat%)(*  
cd "/opt/test"  
put "C:\envars.exe" "envars.exe"  
bye  

( username is 'root' &
password is !@#%RedHat%)(*
)

I tried running the batch file from the command prompt as follows:- C:>ftp -s:F:\testScript.txt

Now I am getting the following error:- "ftp: connect : unknown error number"

Previously I was getting message, "connected" followed by, " connection closed by remote host."

However, I am able to connect to this server using Filezilla.

Please let me know if you are able to figure out what is the issue.

Thanks in advance
Sujit

+1  A: 

Are you sure you want to be connecting to port 22? 21 is the usual FTP port.

Additionally, you should try to execute that script manually (run ftp and type them in yourself) to see where the error occurs. It may be that your firewall is blocking return traffic in active mode (see if Filezilla is running in passive mode).


Based on your comment, you're definitely connecting to a secure FTP server. The ftp.exe program that comes with Windows only does standard FTP.

A quick Google of "ftps client for windows" turns up many possibilities, one of which is a secure FTP client in Putty, a tool we use (and highly recommend) at work. Another is sftp that comes with CygWin.

I don't believe either of these allow you to specify a password other than interactively. They rightly assume that you're using them for security purposes and having a password in plaintext in a script would render the security moot.

Your best option is to set up shared keys the way SSH wants you to. That is the most secure way.

However, if you're more interested in ease of setup rather than security, you can just use expect to await the password prompt and then give your password to the SFTP program. CygWin also comes with expect (Putty doesn't) so I'd suggest using that.

paxdiablo
As per your suggestion I tried each command from ftp prompt as follows:-ftp> open 192.168.1.33 22 Connected to 192.168.1.33. SSH-2.0-OpenSSH_4.3 Connection closed by remote hostWhen I connect without specifying the port 22 I get this error > ftp: connect :Unknown error numberI am trying to use port 22 as filezilla which connects using sftp is able to connect to this server.Please let me know if you are able to figure out something from here.
sujimon
Yes the transfer mode in Filezilla is 'Passive' and option 'Allow fallback to other mode on failure' is selected.
sujimon
Meanwhile the method suggested in the following thread by 'Hansup' seems to work for me when I try it from command line. <http://stackoverflow.com/questions/3754928/sftp-upload-with-vba>
sujimon
A: 

You should connect on port 21. Port 22 is for SSH connections, which explains why Filezilla can connect as it supports FTPS (FTP over SSH).

David
Please let me know what are my options if I want to connect using FTPS.
sujimon
You can use WinSCP to connect to an FTPS server.
David
A: 

Without commenting on the appropriatness (or otherwise) of your password, several of the characters you used may be interpreted as special characters by batch files. Check (perhaps via ECHO statement) and make sure that that particular string is being passed through as-is.

Philip Kelley
Thanks Phil! I had to add an extra % to prevent the % in the password from being interpreted as special char.
sujimon