search
Japanese Chinese Nederlands Espanol Italiano Deutsch Francais Twitter Rss Feeds
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsFAQs
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Operating SystemsArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

View Other VB.NET Posts   Ask New Question 
Download a file on a UNIX FTP Server with VB NET
Nicolas Zenou posted at Monday, July 24, 2006 10:23 AM
Hye,

I m trying to download a file on a UNIX FTP server on a VB.NET application, but I always get the message : 

"The remote server returned an error : (503) bad sequence of commands."

I am actually using this piece code: 

Dim downloadRequest As FtpWebRequest = CType(WebRequest.Create(myUri), FtpWebRequest)

downloadRequest.UsePassive = False
     
 Dim downloadResponse As FtpWebResponse = CType(downloadRequest.GetResponse, FtpWebResponse)
myResponseStream = downloadResponse.GetResponseStream()


And its raising the exception when I launch de GetResponseStream() method.

Does anyone know why it's not working with a UNIX server while it's work on a WINDOWS FTP server ?

 
  Use FtpWebRequest to download a file
Rocky Guls replied at Monday, July 24, 2006 10:31 AM
Reason for ur error:
 This response indicates that a remote SMTP Server or client is attempting to conduct a series of SMTP transactions out of sequence. 


Alternate Code:
=========

<PRE lang=vbnet>'Values to use
Const localFile As String = "C:\myfile.bin"
Const remoteFile As String = "/pub/myftpfile.bin"
Const host As String = "ftp://ftp.myhost.com"
Const username As String = "myuserid"
Const password As String = "mypassword"

'1. Create a request: must be in ftp://hostname format, 
'   not just ftp.myhost.com
Dim URI As String = host & remoteFile
Dim ftp As System.Net.FtpWebRequest = _
    CType(FtpWebRequest.Create(URI), FtpWebRequest)

'2. Set credentials
ftp.Credentials = New _
    System.Net.NetworkCredential(username, password)

'3. Settings and action
ftp.KeepAlive = False
'we want a binary transfer, not textual data
ftp.UseBinary = True
'Define the action required (in this case, download a file)
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

'4. If we were using a method that uploads data e.g. UploadFile
'   we would open the ftp.GetRequestStream here an send the data

'5. Get the response to the Ftp request and the associated stream
Using response As System.Net.FtpWebResponse = _
      CType(ftp.GetResponse, System.Net.FtpWebResponse)
  Using responseStream As IO.Stream = response.GetResponseStream
    'loop to read & write to file
    Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
      Dim buffer(2047) As Byte
      Dim read As Integer = 0
      Do
        read = responseStream.Read(buffer, 0, buffer.Length)
        fs.Write(buffer, 0, read)
      Loop Until read = 0 'see Note(1)
      responseStream.Close()
      fs.Flush()
      fs.Close()
    End Using
    responseStream.Close()
  End Using
  response.Close()
End Using

'6. Done! the Close happens because ftp goes out of scope
'   There is no .Close or .Dispose for FtpWebRequest</PRE>

http://www.codeproject.com/vb/net/FtpClient.asp

HTH
 
that's ok now!
Nicolas Zenou replied at Monday, July 24, 2006 10:55 AM
Thanks for this one.
These two lines saved me:

ftp.KeepAlive = False 
ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile 

And now it works fine.

Thanks.