Set Attributes using ftp 2.0 and vb.net

0 votes
asked Aug 11, 2011 by NickS (170 points)
edited May 24, 2012

Hi

I am uploading files to an Apache server. The files have an attribute of 644. I need people other than the person who uploaded the files to have access to them so I need to change the attribute to 666. Is this possible using the software if so how?

Thanks

Nick Steele

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Aug 12, 2011 by Lukas Matyska (60,650 points)
edited May 3, 2016 by Lukas Pokorny
 
Best answer

Altough there is no standard 'Change File Attributes' FTP command, many servers support SITE CHMOD extension. To issue a CHMOD command, use the following code:

string response = client.Site("CHMOD 666 file.txt");

If you need to parse FTP response for future processing, following code can help you (it is equivalent of the previous one line sample code):


client.SendCommand("SITE CHMOD 666 file.txt");
FtpResponse response = client.ReadResponse();
commented Aug 12, 2011 by NickS (170 points)
edited Oct 11, 2011

That worked thanks

commented May 6, 2012 by zalmyc (100 points)
edited May 6, 2012

I'm very new to VB. Can you please tell me how to get the "Site" property (I rely heavily on intellisense)?

commented May 6, 2012 by Jan Sotola (17,670 points)
edited May 6, 2012

The "Site" is not a property, it is a method. It is used for executing a command specific for the current FTP server. An argument of the Site method is a string with the command - e.g. "CHMOD 666 file.text".

Each FTP server has a specific set of supportet SITE commands (and some FTP servers do not support SITE command at all). E.g. the Appache FTP server accepts following SITE commands: http://mina.apache.org/ftpserver/site-commands.html Or the Titan FTP server accepts following SITE commands: http://titanftp.com/support/titanftp/v8/webhelp/SITE.htm

commented May 23, 2012 by zalmyc (100 points)
edited May 23, 2012

Thanks Jan. I know that my ftp server supports the SITE command, and when I use FileZilla to change folder permissions, I see that it executes Command: SITE CHMOD 777 Yellow_Folder

Would you be kind enough to tell me how to issue this command within visual basic? I have tried what seems to be everything.

So far, I have this:

    Dim host As String = "ftp://0.0.0.0/images/2012/"  '0.0.0.0 is not the actual IP'
    Const username As String = "user"
    Const password As String = "pass"
    Dim ftp As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(host)
    ftp.Credentials = New System.Net.NetworkCredential(username, password)
    ftp.Method = "SITE CHMOD 777 Yellow_Folder"
    Dim response As System.Net.FtpWebResponse = CType(ftp.GetResponse(), System.Net.FtpWebResponse)
    response.Close()

When I execute this, I get an exception that the method isn't supported (parameter: value). I'm pretty sure I'm not doing something correct rather than the actual CHMOD command not being supported. I see that the built-in commands such as PrintWorkingDirectory and MakeDirectory are just strings PWD and MKDir, so I tried setting up a public const CHMOD as string = "SITE CHMOD 777 Yellow_Folder", but it won't let me attach it to the end webrequestmethods.ftp (i.e. I can't write webrequestmethods.ftp.CHMOD.

So I guess my question is, how can I issue the command?

Thanks!

commented May 23, 2012 by Jan Sotola (17,670 points)
edited May 3, 2016 by Lukas Pokorny

I'm afraid sending FTP commands like SITE CHMOD does not work using System.Net.FtpWebRequest (see this article for more details).

Here is a code example, how to do it using Rebex FTP component:

 Dim ftp As Rebex.Net.Ftp = New Rebex.Net.Ftp()

 ftp.Connect("0.0.0.0")
 ftp.Login("user", "password")
 ftp.ChangeDirectory("/images/2012/")

 ftp.SendCommand("SITE CHMOD 777 Yellow_Folder")
 Dim response as Rebex.Net.FtpResponse = ftp.ReadResponse()
 If response.Group <> 2 Then Throw New FtpException(response)

 ftp.Disconnect()
commented May 24, 2012 by zalmyc (100 points)
edited May 24, 2012

Oh well, thanks anyway. I can't see myself getting the Rebex package, as I only really need this particular feature and can't justify that cost. Thanks Jan for all your help.

...