How to create directory on the FTP Server ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolestavi007
    New Member
    • Aug 2008
    • 10

    How to create directory on the FTP Server ?

    Hi,
    I have to create directories on the FTP server. I have tried directory.exist s but it doesnt work.Any other way to create directory on the server.Please help me.
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    what about this Net.WebRequestM ethods.Ftp.Make Directory?

    of course you'd have to set an instance to net,ftpwebreque st and set the method to makedirectory(f irst one up top).

    soo e.g.


    Code:
     
     Dim myftprequest As Net.FtpWebRequest = CType(Net.FtpWebRequest.Create(host), System.Net.FtpWebRequest)
            myftprequest.Credentials = New System.Net.NetworkCredential(username, password)
            myftprequest.Method = System.Net.WebRequestMethods.Ftp.MakeDirectory
    'code to upload it

    Comment

    • coolestavi007
      New Member
      • Aug 2008
      • 10

      #3
      How to create multiple directory and subdirectory

      Hi
      I have to make directory and subdirectory one into another.
      say creating a Avi directory then in that i have to create another directory kavi in that subdiretcory another and so on.,.....

      plz help me out reg this.

      Comment

      • coolestavi007
        New Member
        • Aug 2008
        • 10

        #4
        Thanks for the reply.....
        it works ......
        but now i have to create multiple subdirectories one into another...
        say
        kavi(subdirecto ry)--->avi(subdirecto ry)---->and so on......

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          I'm sorry, but figure it out for yourself. If you have the code to make a directory, the code for a subdirectory is no different, you just have to change the target.

          You're not going to get everything spoon fed to you here.

          Comment

          • joedeene
            Contributor
            • Jul 2008
            • 579

            #6
            exactly as insertalias said, we cant give you everything, im here to help although i did give you a code sample to get you started, i can continue to giving you answers because i dont know if your just copying and pasting or learning, and plus you have to show us *some* code of yours to get further help, so i will ask how do you want to make the subdirectories ? and what have you done so far, with helping yourself to make this ?

            joedeene

            Comment

            • coolestavi007
              New Member
              • Aug 2008
              • 10

              #7
              okk.....here is the code for FTP ....It is working fine ....but when I am trying to create subdirectories ,it gives an error..

              ------------------------------------------------------------------------------------------------------------------
              Shared Sub main2(ByVal zipdir, ByVal systemname)

              'FTP creadentials'
              Dim servertemp As String = "ftp://hydhtc25116/"
              Dim username As String = "hydhtc25116\ro ot"
              Dim password As String = "infy@123"
              Dim host As String = servertemp

              'Renaming the zip file as the current system date'
              Dim filename As String
              filename = zipdir
              Dim New1 As String
              Dim month1 As String
              Dim year1 As String
              Dim day1 As String
              day1 = DatePart("d", DateTime.Now)
              month1 = DatePart("m", DateTime.Now)
              year1 = DatePart("yyyy" , DateTime.Now)
              New1 = systemname + "_" + day1 + "-" + month1 + "-" + year1

              'Declaring the FTP zip filename as the current system Date'
              Dim remoteFile As String = "/" & New1 & ".zip"


              '1. Create a request: must be in ftp://hostname format'
              Dim URI As String = host & remoteFile
              Dim ftp As Net.FtpWebReque st = CType(Net.FtpWe bRequest.Create (URI), Net.FtpWebReque st)

              '2. Set credentials

              ftp.Credentials = New System.Net.Netw orkCredential(u sername, password)

              '3. Settings and action

              ftp.KeepAlive = False

              '4. we want a binary transfer, not textual data

              ftp.UseBinary = True

              '5. Define the action required (in this case, download a file)

              ftp.Method = System.Net.WebR equestMethods.F tp.UploadFile

              '6. Reading the content of the zip file'

              Dim bFile() As Byte = System.IO.File. ReadAllBytes(fi lename & "/" & New1 & ".zip")
              Dim clsStream As System.IO.Strea m = ftp.GetRequestS tream()

              'Writing the content of the file'
              clsStream.Write (bFile, 0, bFile.Length)
              clsStream.Close ()
              clsStream.Dispo se()
              clsStream.Flush ()



              End Sub
              -----------------------------------------------------------------------------------------------------------------
              here is the code for logic of directory which i want to create on server...


              ---------------------------------------------------------------------------------------------------------

              Sub Main()
              Dim str As String = "C:\ProgramFile s\Ext\ABC\Stv\t ext.txt"
              Dim newstr As String = str.Substring(0 , 1)
              Console.WriteLi ne(newstr)
              Dim new1 As String = str.Substring(3 , str.LastIndexOf ("\") - 2)
              Console.WriteLi ne(new1)
              If Not Directory.Exist s("C:\C\" & new1) Then
              Directory.Creat eDirectory("C:\ C\" & new1)
              End If


              End Sub

              --------------------------------------------------------------------------------------------------------------

              Comment

              Working...