Results 1 to 4 of 4

Thread: FTPWebrequest won't make directory

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    5

    Question FTPWebrequest won't make directory

    Hey,
    I have this code:
    Code:
     Dim Dir = ftphost & d.ToString("/yyyy")
                Dim ftpReq As FtpWebRequest = WebRequest.Create(Dir)
                ftpReq.Credentials = New NetworkCredential(ftpun, ftppass)
                ftpReq.Method = WebRequestMethods.Ftp.MakeDirectory
    
                Dir = (ftphost & d.ToString("/yyyy/") & d.ToString("MM"))
    
                Dim a As FtpWebRequest = WebRequest.Create(Dir)
                a.Credentials = New NetworkCredential(ftpun, ftppass)
                a.Method = WebRequestMethods.Ftp.MakeDirectory
    
                Dir = ftphost & d.ToString("/yyyy/") & d.ToString("MM/") & d.ToString("dd")
                Dim c As FtpWebRequest = WebRequest.Create(Dir)
                c.Credentials = New NetworkCredential(ftpun, ftppass)
                c.Method = WebRequestMethods.Ftp.MakeDirectory
                MsgBox("DONE")
    Assuming that ftpun and ftppass is correct why won't the directory be made. It does not output all it does is shows as done but its not made a folder. Why wont it work? I have tried using functions and different methods but it still wont work.
    Thanks,
    Zacy5000

  2. #2
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: FTPWebrequest won't make directory

    Just a quick thought since we don't have a stack trace here. Have you logged into your FTP server with an FTP Client (filezilla, command prompt, etc) and tried to make a directory with those credentials? Does it work or not work?
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    5

    Re: FTPWebrequest won't make directory

    Yes I have and it works perfect on filezilla.

  4. #4
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: FTPWebrequest won't make directory

    This is a private sub that creates an FTP directory. You could easily turn it into a function as well if you would like a little more control of the result. If you are using a GUI though, it should be fine. Try it out and let us know how you fare.

    Code:
    Imports System.Net
    Imports System.IO
    
    Private Sub MakeDir(ByVal dirName As String, ByVal ServerIP as String, ByVal UserId as String, ByVal Password as String)
    
           Dim reqFTP As FtpWebRequest = Nothing
           Dim ftpStream As Stream = Nothing
           Try
               reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ServerIP + "/" + dirName)), FtpWebRequest)
               reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory
               reqFTP.UseBinary = True
               reqFTP.Credentials = New NetworkCredential(UserId, Password)
               Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
               ftpStream = response.GetResponseStream()
               ftpStream.Close()
               response.Close()
           Catch ex As Exception
               If ftpStream IsNot Nothing Then
                   ftpStream.Close()
                   ftpStream.Dispose()
               End If
               Throw New Exception(ex.Message.ToString())
           End Try
       End Sub
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width