PHP脚本:上传ftp文件到指定目录

使用php可以很容易的实现向ftp服务器上传文件的功能,下面的脚本就实现了这个功能:

    $daily_script_name = "file-name-to-upload";
    $ftp_host = "your-ftp-host";
    $uname = "user-name";

使用php可以很容易的实现向ftp服务器上传文件的功能,下面的脚本就实现了这个功能:

    $daily_script_name = "file-name-to-upload";
    $ftp_host = "your-ftp-host";
    $uname = "user-name";
    $pass = '********';
    $remote = "your-remote-file-location/$daiy_script_name";

    $ftpc = ftp_connect($ftp_host);
    if (ftp_login($ftpc, $uname, $pass)) {
        print ("FTP logged in…
\n");
    } else {
        print ("FTP could not login.
\n");
    }
    if (ftp_put($ftpc, $remote, $daily_script_name, FTP_BINARY)) {
        print ("File was uploaded.
\n");
    } else {
        print ("File was not uploaded.
\n");
    }
    ftp_close($ftpc);

Leave a Reply

Your email address will not be published. Required fields are marked *