{"id":3295,"date":"2012-08-14T10:15:07","date_gmt":"2012-08-14T08:15:07","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3295"},"modified":"2013-06-26T10:40:28","modified_gmt":"2013-06-26T08:40:28","slug":"ftp-file-and-folder-permissions","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/ftp-file-and-folder-permissions","title":{"rendered":"FTP file and folder permissions"},"content":{"rendered":"<p>You can access remote file or folder permissions using Limilabs <a href=\"\/ftp\">.NET FTP library<\/a>. First you should learn how to connect and <a href=\"\/blog\/download-file-using-ftp\">download files from FTP server<\/a>.<\/p>\n<p>It is important to realize that originally FTP protocol didn&#8217;t have the <strong>concept of file\/folder permissions<\/strong> build-in directly.<\/p>\n<p><em>LIST<\/em> command, that allowed listing contents of the remote server, was build around system listing commands: <em>ls<\/em> on UNIX\/LINUX machines, <em>dir <\/em>on Windows.<br \/>\n<em>ls <\/em> returns file permissions divided into 3 groups: Owning user, owning group and others e.g.: rwxr&#8211;rw-.<\/p>\n<p>When using Ftp.dll <em>Ftp.List<\/em> and <em>Ftp.GetList<\/em> methods with <strong>UNIX FTP server <\/strong> (or a server that imitates <em>ls<\/em> output for <em>LIST<\/em> command) you can access these UNIX permissions using <em>UnixPermissions <\/em>property on <em>FtpItem <\/em>object:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nList&lt;FtpItem&gt; items = client.List();\r\nUnixPermissionSet set = items&#x5B;0].UnixPermissions;\r\n\r\nbool ownerCanRead = (set.OwnerUser | UnixPermission.Read) != 0;\r\nbool groupCanRead = (set.OwnerGroup | UnixPermission.Read) != 0;\r\nbool othersCanRead = (set.Others | UnixPermission.Read) != 0;\r\n\r\nbool ownerCanWrite = (set.OwnerUser | UnixPermission.Write) != 0;\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim items As List(Of FtpItem) = client.List()\r\nDim &#x5B;set] As UnixPermissionSet = items(0).UnixPermissions\r\n\r\nDim ownerCanRead As Boolean = (&#x5B;set].OwnerUser Or UnixPermission.Read) &lt;&gt; 0\r\nDim groupCanRead As Boolean = (&#x5B;set].OwnerGroup Or UnixPermission.Read) &lt;&gt; 0\r\nDim othersCanRead As Boolean = (&#x5B;set].Others Or UnixPermission.Read) &lt;&gt; 0\r\n\r\nDim ownerCanWrite As Boolean = (&#x5B;set].OwnerUser Or UnixPermission.Write) &lt;&gt; 0\r\n<\/pre>\n<h2>MLSD and perm fact<\/h2>\n<p>As FTP protocol evolved, <em>MLSD<\/em> command was introduced with <a href=\"\/ftp\/rfc\/3659\">RFC 3659<\/a>.<\/p>\n<p><em>MLSD<\/em> standardized the way listings are returned from the server. It introduced facts concept, and in particular perm fact.<br \/>\n<em>Ftp.GetList<\/em> method uses <em>MLSD<\/em> command if it is available, that is if MLST extension is supported and advertised by the remote server. It is possible to force this command to be used by calling <em>Ftp.MLSD<\/em> method directly.<\/p>\n<p>You can access <strong>parsed version of perm fact<\/strong> using <em>FtpItem.Permission<\/em> property:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nList&lt;FtpItem&gt; items = client.GetList();\r\nList&lt;FtpPermission&gt; permissions = items&#x5B;0].Permissions;\r\n\r\nbool canRead = permissions.Contains(FtpPermission.Read);\r\nbool canWrite = permissions.Contains(FtpPermission.Write);\r\nbool canCreateFile = permissions.Contains(FtpPermission.CreateFile);\r\nbool canChangeFolder = permissions.Contains(FtpPermission.ChangeFolder);\r\n\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim items As List(Of FtpItem) = client.GetList()\r\nDim permissions As List(Of FtpPermission) = items(0).Permissions\r\n\r\nDim canRead As Boolean = permissions.Contains(FtpPermission.Read)\r\nDim canWrite As Boolean = permissions.Contains(FtpPermission.Write)\r\nDim canCreateFile As Boolean = permissions.Contains(FtpPermission.CreateFile)\r\nDim canChangeFolder As Boolean = permissions.Contains(FtpPermission.ChangeFolder)\r\n<\/pre>\n<p>As you can see Ftp permissions can contain additional information such as if you can select particular folder or create a file within.<\/p>\n<h2>Changing the permissions<\/h2>\n<p>There is <strong>no standardized way of changing the permissions<\/strong>. You&#8217;ll need <em>SITE <\/em>command (this command is used by the server to provide services specific to his system but not sufficiently universal to be included as commands in protocol) and <em>CHMOD <\/em> (again UNIX command).<\/p>\n<p>Limilabs <a href=\"\/ftp\">.NET FTP library<\/a> contains useful shortcut for that &#8211; <em>SiteChangeMode<\/em> method:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nclient.SiteChangeMode(&quot;file.txt&quot;, new UnixPermissionSet(UnixPermission.Write));\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nclient.SiteChangeMode(&quot;file.txt&quot;, New UnixPermissionSet(UnixPermission.Write))\r\n<\/pre>\n<p>Note that the same <em>UnixPermissionSet<\/em> class can is used that is returned by <em>FtpItem.UnixPermissions<\/em> property<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can access remote file or folder permissions using Limilabs .NET FTP library. First you should learn how to connect and download files from FTP server. It is important to realize that originally FTP protocol didn&#8217;t have the concept of file\/folder permissions build-in directly. LIST command, that allowed listing contents of the remote server, was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[15,22,80,57],"class_list":["post-3295","post","type-post","status-publish","format-standard","hentry","category-ftp-dll","tag-c","tag-ftp","tag-ftp-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3295"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3295"}],"version-history":[{"count":10,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3295\/revisions"}],"predecessor-version":[{"id":4138,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3295\/revisions\/4138"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}