FTP upload

来源:互联网 发布:围住神经猫源码 编辑:程序博客网 时间:2024/05/17 03:28
<?php


//利用ftp创建目录
$path ='/public_html/satei/files/force/';


$ftp_server='crownjewel.jp';
$ftp_user_name='crownjewel';
$ftp_user_pass='5aFsMhGc';




// 接続を確立する
$conn_id = ftp_connect($ftp_server);


// ユーザー名とパスワードでログインする
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);




//$file =$path. '/newfile.csv';
//$file='C:\gankenrin\201712\test7.csv';//成功


//$file='C:\gankenrin\201712\force\kaitori01.csv';//成功








//Localにて、dir存在チェック
//作成したいディレクトリ(のパス)
//$directory_path = "C:/gankenrin/201712/force";    //この場合、一つ上の階層に「force」というディレクトリを作成する
$directory_path = "C:/force";
//「$directory_path」で指定されたディレクトリが存在するか確認
if(file_exists($directory_path)){
    //存在したときの処理
    echo "作成しようとしたディレクトリは既に存在します";
}else{
    //存在しないときの処理(「$directory_path」で指定されたディレクトリを作成する)
    if(mkdir($directory_path, 0777)){
        //作成したディレクトリのパーミッションを確実に変更
        chmod($directory_path, 0777);
        //作成に成功した時の処理
        echo "作成に成功しました";
    }else{
        //作成に失敗した時の処理
        echo "作成に失敗しました";
    }
}


$kaitori_no=123456789;
$csvName ='force'.$kaitori_no;
$file = $directory_path.'/'.$csvName.'.csv';//成功


$remote_file = $path.'/'.$csvName.'.csv';




$newpath='public_html/satei/files/force/test';






// ファイルをオープンして既存のコンテンツを取得します




/*
if (file_exists($file)) {
    //echo "The file $file exists";
    //if ($current = @file_get_contents($file)) {
        $current = file_get_contents($file);
        $current .= "Gan Test1233\n";
        file_put_contents($file, $current);
    //}
    
    
    
    
    
} else {
    echo '存在しません';
    echo "The file $file does not exist";
    $file = fopen("C:\gankenrin\201712\test8.csv", "w");
    echo '生成shin';
}
 */


    if ($current = @file_get_contents($file)) {
        $current = file_get_contents($file);      
    }
    $current .= "Gan Test1233\n";
    file_put_contents($file, $current);
    
    
  /*  
$current = file_get_contents($file);
// 新しい人物をファイルに追加します
$current .= "Gan Test1233\n";
// 結果をファイルに書き出します
file_put_contents($file, $current);
  
   */




    
    
    


//@unlink ($file); 
//ftp_delete($ftp_stream, $file);
//ftp_delete($conn_id, $file);


// ファイルをアップロードする
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}


// 接続を閉じる
ftp_close($conn_id); 




?>

原创粉丝点击