Function FTP_Data() '========================================================================= 'FTP from Microsoft Access 'by Matthew V Carmichael 'Craetes FTP Batch File, FTP command file (txt) 'Default directory location of files to upload/download is 'the same location as the mdb file that contains this module. '=========================================================================' On Error GoTo Err_Trap Dim pFile As Long Dim strPath As String Dim strFileName As String Dim ftpServer As String Dim strUserName As String Dim strPassword As String 'Path and Name of file to FTP strPath = CurrentProject.Path & "" strFileName = "Test.mdb" 'Name of file to upload 'FTP Server Settings ftpServer = "Your FTP Server" strUserName = "Your FTP User Name" strPassword = "Your FTP Password" 'Create text file containing FTP commands pFile = FreeFile Open strPath & "FTP_cmd.txt" For Output As pFile Print #pFile, "user" Print #pFile, strUserName Print #pFile, strPassword Print #pFile, "Put " & strFileName 'Use the Put command to upload, use the Get command to download. 'Print #pFile, "Get " & "Your File Name" Print #pFile, "quit" Close pFile 'Create batch file to execute FTP pFile = FreeFile Open strPath & "FTP_Run.bat" For Output As pFile Print #pFile, "ftp -n -s:" & "FTP_cmd.txt " & ftpServer Print #pFile, "Pause" Close pFile 'Execute FTP command Shell strPath & "FTP_Run.bat", 1 Err_Trap_Exit: Exit Function Err_Trap: MsgBox Err.Number & " - " & Err.Description Resume Err_Trap_Exit End Function
Tag Archive for FTP
ACCESS FTP Upload
tar basics
# create tar cvf docs.tar docs2 # extract tar xvf docs.tar
cURL in PHP
/**
* cURL file copy to another server
* This file saved my life when i had to let a file upload synchrom to a different server, no ftp messing around!
*/
$rCurl = curl_init();
/**
* The file to copy
*/
curl_setopt($rCurl, CURLOPT_URL, 'http://www.google.nl/intl/nl_nl/images/logo.gif');
/**
* cURL options dunno what for
*/
curl_setopt($rCurl, CURLOPT_HEADER, false);
/**
* cURL options dunno what for
*/
curl_setopt($rCurl, CURLOPT_BINARYTRANSFER, true);
/**
* cURL options dunno what for
*/
curl_setopt($rCurl, CURLOPT_RETURNTRANSFER, true);
/**
* The php file limit
*/
set_time_limit(300);
/**
* set cURL timeout
*/
curl_setopt($rCurl, CURLOPT_TIMEOUT, 300);
/**
* The file that will be written
*/
$rOutPut = fopen('googlelogo.gif', 'wb');
/**
* Setup the transfer ?
*/
curl_setopt($rCurl, CURLOPT_FILE, $outfile);
/**
* Execute the transfer
*/
curl_exec($rCurl);
/**
* Close the file
*/
fclose($rOutPut);
/**
* Close cURL
*/
curl_close($rCurl);
FTP Uploader
# Import FTP library:
import ftplib
# Connect to the server:
s = ftplib.FTP('server','user','password')
# Open file to send:
f = open('/folder/folder/local_filename','rb')
# Store file on server:
s.storbinary('STOR server_filename', f)
# Close sent file:
f.close()
# Close server connection:
s.quit()
FTP file upload example
// FTP access parameters:
$host = 'ftp.example.org';
$usr = 'example_user';
$pwd = 'example_password';
// file to upload:
$local_file = './example.txt';
$ftp_path = '/data/example.txt';
// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);
// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
// check upload status:
print (!$upload) 'Cannot upload' : 'Upload complete';
print "
";
/*
** Chmod the file (just as example)
*/
// If you are using PHP4 then you need to use this code:
// (because the "ftp_chmod" command is just available in PHP5+)
if (!function_exists('ftp_chmod')) {
function ftp_chmod($ftp_stream, $mode, $filename){
return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
}
}
// try to chmod the new file to 666 (writeable)
if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
print $ftp_path . " chmoded successfully to 666
";
} else {
print "could not chmod $file
";
}
// close the FTP stream
ftp_close($conn_id);
Net::FTP to ftp a file
use Carp; use Net::FTP; my $ip = ...; # Target machine my $local= ...; # local filename croak "$local file is missing !! " unless -f $local; my $remote= ...; # Remote filename my $ftp= Net::FTP->new( $ip ,Port => 21 # Standard port number ,Timeout => 15 # Timeout in seconds ) or croak "Failed to connect to $ip."; my $user= ...; # login user my $pw = ...; # login password $ftp->login( $user, $pw ) or croak "Failed to login."; $ftp->put( $local, $remote) or croak "Failed to <a href="http://ftp.";" >ftp.";</a> $ftp->quit();