Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

FTP download local file

var Client = require('ftp');
  var fs = require('fs');
 
  var c = new Client();
  c.on('ready', function() {
    c.get('foo.txt', function(err, stream) {
      if (err) throw err;
      stream.once('close', function() { c.end(); });
      stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
    });
  });
  // connect to localhost:21 as anonymous
  c.connect();
Comment

download files from ftp

#FTP Server Information - SET VARIABLES
$ftp = "ftp://XXX.com/" 
$user = 'UserName' 
$pass = 'Password'
$folder = 'FTP_Folder'
$target = "C:FolderFolder1"

#SET CREDENTIALS
$credentials = new-object System.Net.NetworkCredential($user, $pass)

function Get-FtpDir ($url,$credentials) {
    $request = [Net.WebRequest]::Create($url)
    $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
    if ($credentials) { $request.Credentials = $credentials }
    $response = $request.GetResponse()
    $reader = New-Object IO.StreamReader $response.GetResponseStream() 
    while(-not $reader.EndOfStream) {
        $reader.ReadLine()
    }
    #$reader.ReadToEnd()
    $reader.Close()
    $response.Close()
}

#SET FOLDER PATH
$folderPath= $ftp + "/" + $folder + "/"

$files = Get-FTPDir -url $folderPath -credentials $credentials

$files 

$webclient = New-Object System.Net.WebClient 
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 
$counter = 0
foreach ($file in ($files | where {$_ -like "*.txt"})){
    $source=$folderPath + $file  
    $destination = $target + $file 
    $webclient.DownloadFile($source, $target+$file)

    #PRINT FILE NAME AND COUNTER
    $counter++
    $counter
    $source
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: The toString() Method 
Javascript :: how i get selected class of li in jquery 
Javascript :: NodeJS Content-Type 
Javascript :: javascript set() method 
Javascript :: nodemailer 
Javascript :: what does json.parse do 
Javascript :: Nuxt.js + Electron 
Javascript :: string equals javascript 
Javascript :: nodejs: router by use express and path package 
Javascript :: what is closure 
Javascript :: blockchain javascript 
Javascript :: != javascript 
Javascript :: Movie-app using react 
Javascript :: js summation 
Javascript :: usereduce 
Javascript :: javascript split multiple values 
Javascript :: take a screenshot javascript of canvas 
Javascript :: javascript array slice() example 
Javascript :: dynamic classname react 
Javascript :: string to array in js 
Javascript :: make a button who disable scrolling down the page react 
Javascript :: Find the count of a letter in a string 
Javascript :: get array element by index javascript 
Javascript :: pass a variable by reference to arrow function 
Javascript :: laravel json eloquent 
Javascript :: Import A Module In ExpressJS 
Javascript :: react native intro slider 
Javascript :: fibonacci series javascript using recursion explanation 
Javascript :: javaScript disable submit button until form is fully validated 
Javascript :: js filter array 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =