{"id":25522,"date":"2019-03-21T08:40:02","date_gmt":"2019-03-21T07:40:02","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=25522"},"modified":"2019-03-21T09:37:39","modified_gmt":"2019-03-21T08:37:39","slug":"scaricamento-file-da-ftp","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/scaricamento-file-da-ftp\/","title":{"rendered":"Scaricamento file da FTP"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' Il seguente script \u00e8 un esempio di come si pu\u00f2 scaricare un file da un server FTP. Pu\u00f2 essere utilizzato semplicemente cambiando i percorsi dei files. Dopo che il file \u00e8 stato scaricato, questo viene anche rielaborato per trasformarlo da file in lunghezza fissa ad un CSV. Si riporta anche questa parte in quanto pu\u00f2 essere utile come esempio per eventuali necessit\u00e0 di rielaborazione.\r\n\r\ndim FTP as System.Net.WebClient\r\n\r\nFTP = new System.Net.WebClient\r\n\r\nFTP.Credentials = new System.Net.NetworkCredential (\"&lt;utente&gt;\",\"&lt;password&gt;\")\r\nDim fileData As Byte() = FTP.DownloadData(\"ftp:\/\/&lt;url&gt;\/&lt;nome file&gt;\")\r\n\r\nDim f As System.io.FileStream = System.IO.File.Create(\"&lt;nome file scaricato&gt;\")\r\nf.Write(fileData, 0, fileData.Length)\r\n\r\nf.Close()\r\n\r\n' Trasforma il file in un CSV\r\nDim fi As System.IO.StreamReader = New system.IO.StreamReader(\"&lt;nome file scaricato&gt;\")\r\nDim fo As System.IO.StreamWriter = New system.IO.StreamWriter(\"&lt;nome file CSV&gt;\")\r\nDim l As String\r\n\r\nWhile Not fi.EndOfStream\r\n            l = fi.ReadLine\r\n \r\n            if not empty( Substr2(l, 25))\r\n                l = Substr2(l, 1, 14) + \",\" + Substr2(l, 15, 1) + \",\" + Substr2(l, 16, 1) + \",\" + Substr2(l, 17, 8) + \",\" + Substr2(l, 25)\r\n\r\n                fo.WriteLine(l)\r\n            end if\r\nEnd While\r\n\r\nfi.Close()\r\nfo.Close()\r\n\r\nDeletefile(\"&lt;nome file scaricato&gt;\")\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Il seguente script \u00e8 un esempio di come si pu\u00f2 scaricare un file da un server FTP. Pu\u00f2 essere utilizzato semplicemente cambiando i percorsi dei files. Dopo che il file \u00e8 stato scaricato, questo viene anche rielaborato per trasformarlo da file in lunghezza fissa ad un CSV. Si riporta anche questa parte in quanto&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[71,82],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/25522"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=25522"}],"version-history":[{"count":0,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/25522\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=25522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=25522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=25522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}