Link to home
Start Free TrialLog in
Avatar of zameer21
zameer21

asked on

How to FTP file using VB.net

I need to FTP a file i created using VB.net.I am writing a console application.
SOLUTION
Avatar of fredmastro
fredmastro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Göran Andersson
Göran Andersson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zameer21
zameer21

ASKER

Hi Greenhost,
i looked at the code in the link you send me,there is no place to put username and password.I need to ftp to a remote host with username and password.
Could just use the class I linked you too.

    '        ' Create an instance of the FTP Class.
    '        'ff = New clsFTP()
 
    '        ' Setup the appropriate properties.
    '        'ff.RemoteHost = "microsoft"
    '        'ff.RemoteUser = "ftpuser"
    '        'ff.RemotePassword = "password"

Hi FredMastro,
I am presenlty thinking of using ur class,i need to test it.I will be only able to do it tomm or day after, as i dont have all the ftp info yet.
To set the user name and password for a WebClient object, you use the Credentials property:

myWebClient.Credentials = New NetworkCredential (username, password);
GreenGhost,
where do u specify the remote host in the code you gave me.
i GOT IT GREENHOST,
Is there way to determine if the file was written succesfully,through code.
UploadMathod returns Byte().What is this byte() array for.
The method returns the response from the server.

I'm not certain what the FTP server returns as response, but I think that it's a message like "250 File action completed". You can use the Encoding.ASCII.GetString to decode the bytes into a string.
GreenGhost:
I can write the file to the FTP server,but byte code returned when i use encoding.ascii.getstring is blank.
I would prefer to have sucees to failure so that i can write to the log.
If there is something wrong, you will get an exception.

The method that I suggested for getting the resonse is also used in the example in the documentation for the UploadFile method:

http://msdn2.microsoft.com/en-us/library/aa329789.aspx
I tried all that i was not particluarly happy with what it returns,
But i found another solution through code that uses FTPWebclient it is better and returns a better code,if you file was transmitted.I will divide points between GreenGhost and FredMastro,I dont like to use other dll,if i could code it myself.
> code that uses FTPWebclient

Do you mean FtpWebRequest?
yes thats correct FTPWEbRequest
Yes, that would work too. The WebClient class is easier to use, but if you want a bit more control, the FtpWebRequest class is fine. Though it should still return the same response from the server for the same operation.