Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created April 1, 2013 19:30
Show Gist options
  • Save msurguy/5287103 to your computer and use it in GitHub Desktop.
Save msurguy/5287103 to your computer and use it in GitHub Desktop.
Using FTP bundle in Laravel
Route::get('ftp', function(){
$ftp = SFTP::make('example.com', 'username', 'password');
// connect to FTP server
if($ftp->connect()) {
print "Connection successful";
// download a file from FTP server
// will download file "somefile.php" and
// save locally as "localfile.php"
if($ftp->get("file.jpg", "file.jpg", FTP_BINARY)) {
print "File downloaded";
} else {
print "Download failed: " . $ftp->error;
}
// upload file to FTP server
// will upload file "local.php" and
// save remotely as "remote.php"
/* if($ftp->put("readme.md", "readme.md")) {
print "Filed uploaded";
} else {
print "Upload failed: " . $ftp->error;
}*/
} else {
// connection failed, display last error
print "Connection failed: " . $ftp->error;
}
// change directory to "/mydir"
// $ftp->cd("mydir");
// set file permissions for file "remote.php"
// $ftp->chmod(0777, "remote.php");
/// delete file "remote.php"
// $ftp->delete("remote.php");
// get list of files/directories in directory "/mydir"
//print_r($ftp->ls("mydir"));
// create directory "/mydir2"
// $ftp->mkdir("mydir2");
// get current directory
// print $ftp->pwd();
// rename file "remote.php" to "rem.php"
// $ftp->rename("remote.php", "rem.php");
// remove directory "/mydir2"
//$ftp->rmdir("mydir2");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment