Vai al contenuto

Invio file da FTP a SFTP


fermat

Messaggi raccomandati

ciao a tutti!

 

dovrei creare un programma che in pratica fa questo: prende dei file su un server FTP e li invia ad un server SFTP.

 

sto decidendo il linguaggio in cui farlo, e visto che uso un mac avevo pensato a Obj-C.

non ho bisogna di chissa quale interfaccia grafica, anzi forse lo faccio solo per terminale.

ma vorrei capire la fattibilità della cosa, e in caso quali librerie mi consigliate!

Link al commento
Condividi su altri siti

  • 3 settimane dopo...
<?php

// Credentials for SFTP
$sftp_username = "username";
$sftp_password = "password";

// Include the SFTP library (http://phpseclib.sourceforge.net/sftp/intro.html)
include('Net/SFTP.php');

// Set the SFTP server
$sftp = new Net_SFTP('www.example.org');

// Login to the SFTP server
if (!$sftp->login($sftp_username, $sftp_password)) {
    exit('Login Failed');
}

// Login and get file from the FTP server
// You may replace the URL with $_GET["file"] and pass it through URL
$ftp_login_file = 'ftp://user:password@example.com/myfile.txt'
$ftp_file = file_get_contents($ftp_login_file);

// Get filename
$sftp_file = explode("/", $sftp_file);
$sftp_file = $sftp_file[count($sftp_file) - 1];

// Upload the file got from the FTP server to the SFTP server naming it with the same name of the FTP file
$sftp->put($sftp_file, $ftp_file);

 

Questo script in PHP fa quello che vuoi, te l'ho scritto ora su due piedi, non l'ho testato ma dovrebbe andare.
Scusa per i commenti in inglese ma scrivo sempre in inglese quando programmo.
 
Fammi sapere se va.

MacBook Pro 15" Retina - mid 2014 - 2.2 GHz - Yosemite

Link al commento
Condividi su altri siti

  • 3 settimane dopo...

Archiviato

Questa discussione è archiviata e chiusa a future risposte.

×
×
  • Crea Nuovo...