Question how to create sub directory on the FTP server?

coolestavi007

New member
Joined
Aug 25, 2008
Messages
3
Programming Experience
1-3
i want to create subdirectory on the server.But unable to create there.

VB.NET:
  Shared Sub main2(ByVal zipdir, ByVal systemname)

        'FTP creadentials'
        Dim servertemp As String = "ftp://hydhtc25116"
        Dim username As String = "hydhtc25116\root"
        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 [url]ftp://hostname[/url] format'
           Dim URI As String = host & remoteFile
            Dim ftp As Net.FtpWebRequest = CType(Net.FtpWebRequest.Create(URI), Net.FtpWebRequest)
      

            '2. Set credentials

            ftp.Credentials = New System.Net.NetworkCredential(username, 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.WebRequestMethods.Ftp.UploadFile

            '6. Reading the content of the zip file'

            Dim bFile() As Byte = System.IO.File.ReadAllBytes(filename & "/" & New1 & ".zip")
            Dim clsStream As System.IO.Stream = ftp.GetRequestStream()

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

    End Sub

here is the logic of directory which i want to create on the server..
VB.NET:
Dim str As String = "C:\ProgramFiles\Ext\ABC\Stv\text.txt"
        Dim newstr As String = str.Substring(0, 1)
        Console.WriteLine(newstr)
        Dim new1 As String = str.Substring(3, str.LastIndexOf("\") - 2)
        Console.WriteLine(new1)
     


        If Not Directory.Exists("C:\C\" & new1) Then
            Directory.CreateDirectory("C:\C\" & new1)
        End If


plz help me out..
 
i want to create subdirectory on the server.But unable to create there.
Set Method to create directory:
WebRequestMethods.Ftp.MakeDirectory
I think WebClient (or My.Computer.Network.) also will auto-create dir when uploading a file if that is what you want.
 
Thanks john.
But still it is not working..
Its giving an error msg that "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
 
MakeDirectory giving 550? 550 may also mean "access denied". I can't tell what's wrong, but if I'm not mistaken you have to create each subfolder in succession, for example to make ftp://ftpsite.com/dir1/dir2 first ftp://ftpsite.com/dir1 must exist.
 
Thanks john,
well i have done the same things what u have written there...but still it is not working....
any clue.....why it is happening???
 
Back
Top