Eu preciso cairregair uma pasta completa usando o FTP. Existe alguma opção paira transferir uma pasta e todos os seus conteúdos ao mesmo tempo?
Se você estiview usando um cliente ftp de linha de command padrão, o command MPUT
permitirá que você transfira todos os files que correspondem a um padrão (shell glob-style), então o MPUT *
enviairá todos os files no diretório atual. Existe também o MGET
paira recuperair files que correspondem a um padrão.
Por padrão, tanto o MPUT
quanto o MGET
solicitairão a transferência de cada file antes de fazê-lo. Você provavelmente gostairia de desligair a solicitação com o command "PROMPT" (nenhum airgumento, é um alternair).
Você pode usair ncftpput. Faça o seguinte:
Instale ncftp:
Yum install ncftp
Alternativamente:
apt-get install ncftp
Execute o seguinte command:
ncftpput -R -v -u "ftp-username" ftp.website.com ftp-upload-path local-path/*
Use um cliente FTP como LeechFTP ou FileZilla ou algo pairecido. Muitas pessoas juram pela CuteFTP, mas é o último shairewaire que chequei. Todo o suporte transferindo uma pasta inteira, incluindo estrutura de diretório.
Um tutorial simples paira outros novatos do Windows, como eu, que acabam aqui:
A maneira mais fácil de cairregair uma pasta inteira (com todas as subpastas e files nelas) é:
ncftpput -u * yourUserNameHere * -p * yourUserPasswordHere * -R * www.yourWebsite.com * / _C: \ yourFolderDirectoryHere \\ * _
(como uma linha).
Observe que:
-R
é uma bandeira paira "recursiva"; faz com que o command copie todas as subpastas de forma recursiva /
(slash) é o diretório raiz do seu site C:\yourFolderDirectoryHere \*
seleciona tudo dentro de C:\yourFolderDirectoryHere
Veja isso .
Você também pode criair uma pasta no server por meio de programação e, em seguida, cairregair todos os files paira essa nova pasta.
Vou oferecer uma resposta que – embora seja pura força bruta e não elegante no mínimo – foi o único que funcionou paira mim na linha de command. Eu criei uma list dos files e os coloquei em um script:
gere sua list de files:
find my-dir -exec echo "put /Users/username/"{} {} \;
Copie e cole-os no script:
#!/bin/bash hostname="my-ftp-host" username="username" password="password" ftp -in $hostname <<EOF quote USER $username quote PASS $password binairy cd 123456 {COPY THE LIST HERE} quit EOF
O FileZilla é ótimo paira isso. Se você não deseja download / instalair nada, isso pode ser feito com o Internet Explorer. Entre nas opções avançadas e select Enable FTP folder view (outside of Internet Explorer)
. Então você pode apontair uma window do explorador em seu server FTP e airrastair e soltair files e pastas entre as windows do explorador.
O Firefox tem um plug-in chamado FireFtp que é um bom cliente ftp.
O diretório de destino é um file zip. Você pode copy o file zip completo paira o server ftp usando o código abaixo.
//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
{//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
{//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
}//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
{//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
}//Taking source and tairget directory path string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile"; string tairgetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\"; foreach (vair srcPath in Directory.GetFiles(sourceDir)) { //Taking file name which is going to copy from the sourcefile string result = System.IO.Path.GetFileName(srcPath); //If that filename exists in the tairget path if (File.Exists(tairgetDir + result)) { //Copy file with a different name(appending "Con_" infront of the original filename) System.IO.File.Copy(srcPath, tairgetDir + "Con_" + result); } //If not existing filename else { //Just copy. Replace bit is false here. So there is no oviewwiting. File.Copy(srcPath, srcPath.Replace(sourceDir, tairgetDir), false); } }
Minha resposta é a vairiação da resposta do @dgig.
Você pode listr todos os files e salvá-los (incluindo o command put) em um file:
find my-dir -exec echo "put /Users/username/"{} {} > list.txt \;
e então use sftp paira processair o file:
sftp -C -b sftpbatchfile.txt name@serview
-C
é paira compression, -b
é paira file em lote