Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. FTP Problem

FTP Problem

Scheduled Pinned Locked Moved Visual Basic
helpsysadmintutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael101
    wrote on last edited by
    #1

    Hi Everyone, I've got an FTP problem. I've been trying to make my own FTP program but it doesn't quite work and I'm not sure why. Dim FileName As String = xmlFileName Dim ftpServerIP = "202.62.33.220" Dim fileInf As New FileInfo(FileName) Dim uri As String = "ftp://" + ftpServerIP + "/" + fileInf.Name Dim reqFTP As FtpWebRequest ' Create FtpWebRequest object from the Uri provided reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ftpServerIP + "/" + fileInf.Name)), FtpWebRequest) MsgBox("ftp://" + ftpServerIP + "/" + fileInf.Name) ' Provide the WebPermission Credintials reqFTP.Credentials = New NetworkCredential("MHR\administrator", "sbanks@#@") ' By default KeepAlive is true, where the control connection is not closed ' after a command is executed. reqFTP.KeepAlive = False ' Specify the command to be executed. reqFTP.Method = WebRequestMethods.Ftp.UploadFile ' Specify the data transfer type. reqFTP.UseBinary = True ' Notify the server about the size of the uploaded file reqFTP.ContentLength = fileInf.Length ' The buffer size is set to 2kb Dim buffLength As Integer = 2048 Dim buff As Byte() = New Byte(buffLength - 1) {} Dim contentLen As Integer ' Opens a file stream (System.IO.FileStream) to read the file to be uploaded Dim fs As FileStream = fileInf.OpenRead() 'Try ' Stream to which the file to be upload is written Dim strm As Stream = reqFTP.GetRequestStream() ' Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength) ' Till Stream content ends While contentLen <> 0 ' Write Content from the file stream to the FTP Upload Stream ******strm.Write(buff, 0, contentLen)********* contentLen = fs.Read(buff, 0, buffLength) End While ' Close the file stream and the Request Stream strm.Close() fs.Close() 'Catch ex As Exception 'MsgBox(ex.Message, "Upload Error") 'End Try Where all the stars are is where the error occurs. The error message is this: (421) Service not available, closing control connection. Does anyone have any ideas? I was thinking it was something to do with no port declaration but I'm try to find out how to declare one to see if that fixes the problem.

    _ 1 Reply Last reply
    0
    • M Michael101

      Hi Everyone, I've got an FTP problem. I've been trying to make my own FTP program but it doesn't quite work and I'm not sure why. Dim FileName As String = xmlFileName Dim ftpServerIP = "202.62.33.220" Dim fileInf As New FileInfo(FileName) Dim uri As String = "ftp://" + ftpServerIP + "/" + fileInf.Name Dim reqFTP As FtpWebRequest ' Create FtpWebRequest object from the Uri provided reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ftpServerIP + "/" + fileInf.Name)), FtpWebRequest) MsgBox("ftp://" + ftpServerIP + "/" + fileInf.Name) ' Provide the WebPermission Credintials reqFTP.Credentials = New NetworkCredential("MHR\administrator", "sbanks@#@") ' By default KeepAlive is true, where the control connection is not closed ' after a command is executed. reqFTP.KeepAlive = False ' Specify the command to be executed. reqFTP.Method = WebRequestMethods.Ftp.UploadFile ' Specify the data transfer type. reqFTP.UseBinary = True ' Notify the server about the size of the uploaded file reqFTP.ContentLength = fileInf.Length ' The buffer size is set to 2kb Dim buffLength As Integer = 2048 Dim buff As Byte() = New Byte(buffLength - 1) {} Dim contentLen As Integer ' Opens a file stream (System.IO.FileStream) to read the file to be uploaded Dim fs As FileStream = fileInf.OpenRead() 'Try ' Stream to which the file to be upload is written Dim strm As Stream = reqFTP.GetRequestStream() ' Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength) ' Till Stream content ends While contentLen <> 0 ' Write Content from the file stream to the FTP Upload Stream ******strm.Write(buff, 0, contentLen)********* contentLen = fs.Read(buff, 0, buffLength) End While ' Close the file stream and the Request Stream strm.Close() fs.Close() 'Catch ex As Exception 'MsgBox(ex.Message, "Upload Error") 'End Try Where all the stars are is where the error occurs. The error message is this: (421) Service not available, closing control connection. Does anyone have any ideas? I was thinking it was something to do with no port declaration but I'm try to find out how to declare one to see if that fixes the problem.

      _ Offline
      _ Offline
      _Fandango_
      wrote on last edited by
      #2

      Hm, code looks correct on a quick view. Since you provided user/pass for that ftp server i tried a connection and got: E:\WINDOWS>ftp ftp> open 202.62.33.220 Verbindung mit 202.62.33.220 wurde hergestellt. Verbindung beendet durch Remotehost. ("Connection terminated by remote host") Connection with an ftp client(ultrafxp): Network subsystem is unusable Seems to be a server issue, try your code on another server to see if code is working :p

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups