mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Don't // Check if file_name is '.' or '..'
This commit is contained in:
@@ -172,6 +172,10 @@ impl FtpFileTransfer {
|
|||||||
Err(_) => 0,
|
Err(_) => 0,
|
||||||
};
|
};
|
||||||
let file_name: String = String::from(metadata.get(8).unwrap().as_str());
|
let file_name: String = String::from(metadata.get(8).unwrap().as_str());
|
||||||
|
// Check if file_name is '.' or '..'
|
||||||
|
if file_name.as_str() == "." || file_name.as_str() == ".." {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
let mut abs_path: PathBuf = PathBuf::from(path);
|
let mut abs_path: PathBuf = PathBuf::from(path);
|
||||||
let extension: Option<String> = match abs_path.as_path().extension() {
|
let extension: Option<String> = match abs_path.as_path().extension() {
|
||||||
None => None,
|
None => None,
|
||||||
@@ -510,7 +514,7 @@ impl FileTransfer for FtpFileTransfer {
|
|||||||
) -> Result<Box<dyn Write>, FileTransferError> {
|
) -> Result<Box<dyn Write>, FileTransferError> {
|
||||||
match &mut self.stream {
|
match &mut self.stream {
|
||||||
Some(stream) => match stream.put_with_stream(&file_name.to_string_lossy()) {
|
Some(stream) => match stream.put_with_stream(&file_name.to_string_lossy()) {
|
||||||
Ok(writer) => Ok(Box::new(writer)),
|
Ok(writer) => Ok(Box::new(writer)), // NOTE: don't use BufWriter here, since already returned by the library
|
||||||
Err(err) => Err(FileTransferError::new_ex(
|
Err(err) => Err(FileTransferError::new_ex(
|
||||||
FileTransferErrorType::FileCreateDenied,
|
FileTransferErrorType::FileCreateDenied,
|
||||||
format!("{}", err),
|
format!("{}", err),
|
||||||
@@ -529,7 +533,7 @@ impl FileTransfer for FtpFileTransfer {
|
|||||||
fn recv_file(&mut self, file: &FsFile) -> Result<Box<dyn Read>, FileTransferError> {
|
fn recv_file(&mut self, file: &FsFile) -> Result<Box<dyn Read>, FileTransferError> {
|
||||||
match &mut self.stream {
|
match &mut self.stream {
|
||||||
Some(stream) => match stream.get(&file.abs_path.as_path().to_string_lossy()) {
|
Some(stream) => match stream.get(&file.abs_path.as_path().to_string_lossy()) {
|
||||||
Ok(reader) => Ok(Box::new(reader)),
|
Ok(reader) => Ok(Box::new(reader)), // NOTE: don't use BufReader here, since already returned by the library
|
||||||
Err(err) => Err(FileTransferError::new_ex(
|
Err(err) => Err(FileTransferError::new_ex(
|
||||||
FileTransferErrorType::NoSuchFileOrDirectory,
|
FileTransferErrorType::NoSuchFileOrDirectory,
|
||||||
format!("{}", err),
|
format!("{}", err),
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ use crate::utils::lstime_to_systime;
|
|||||||
// Includes
|
// Includes
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ssh2::{Channel, Session};
|
use ssh2::{Channel, Session};
|
||||||
use std::io::{Read, Write};
|
use std::io::{BufReader, BufWriter, Read, Write};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
@@ -176,6 +176,10 @@ impl ScpFileTransfer {
|
|||||||
true => self.get_name_and_link(metadata.get(8).unwrap().as_str()),
|
true => self.get_name_and_link(metadata.get(8).unwrap().as_str()),
|
||||||
false => (String::from(metadata.get(8).unwrap().as_str()), None),
|
false => (String::from(metadata.get(8).unwrap().as_str()), None),
|
||||||
};
|
};
|
||||||
|
// Check if file_name is '.' or '..'
|
||||||
|
if file_name.as_str() == "." || file_name.as_str() == ".." {
|
||||||
|
return Err(())
|
||||||
|
}
|
||||||
let mut abs_path: PathBuf = PathBuf::from(path);
|
let mut abs_path: PathBuf = PathBuf::from(path);
|
||||||
let extension: Option<String> = match abs_path.as_path().extension() {
|
let extension: Option<String> = match abs_path.as_path().extension() {
|
||||||
None => None,
|
None => None,
|
||||||
@@ -467,7 +471,7 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
let p: PathBuf = self.wrkdir.clone();
|
let p: PathBuf = self.wrkdir.clone();
|
||||||
match self.perform_shell_cmd_with_path(
|
match self.perform_shell_cmd_with_path(
|
||||||
p.as_path(),
|
p.as_path(),
|
||||||
format!("unset LANG; ls -l \"{}\"", path.display()).as_str(),
|
format!("unset LANG; ls -la \"{}\"", path.display()).as_str(),
|
||||||
) {
|
) {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
// Split output by (\r)\n
|
// Split output by (\r)\n
|
||||||
@@ -584,7 +588,12 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
let p: PathBuf = self.wrkdir.clone();
|
let p: PathBuf = self.wrkdir.clone();
|
||||||
match self.perform_shell_cmd_with_path(
|
match self.perform_shell_cmd_with_path(
|
||||||
p.as_path(),
|
p.as_path(),
|
||||||
format!("mv -f \"{}\" \"{}\"; echo $?", path.display(), dst.display()).as_str(),
|
format!(
|
||||||
|
"mv -f \"{}\" \"{}\"; echo $?",
|
||||||
|
path.display(),
|
||||||
|
dst.display()
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
) {
|
) {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
// Check if output is 0
|
// Check if output is 0
|
||||||
@@ -703,7 +712,7 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
(mtime, atime)
|
(mtime, atime)
|
||||||
};
|
};
|
||||||
match session.scp_send(file_name, mode, local.size as u64, Some(times)) {
|
match session.scp_send(file_name, mode, local.size as u64, Some(times)) {
|
||||||
Ok(channel) => Ok(Box::new(channel)),
|
Ok(channel) => Ok(Box::new(BufWriter::with_capacity(8192, channel))),
|
||||||
Err(err) => Err(FileTransferError::new_ex(
|
Err(err) => Err(FileTransferError::new_ex(
|
||||||
FileTransferErrorType::ProtocolError,
|
FileTransferErrorType::ProtocolError,
|
||||||
format!("{}", err),
|
format!("{}", err),
|
||||||
@@ -726,7 +735,7 @@ impl FileTransfer for ScpFileTransfer {
|
|||||||
// Set blocking to true
|
// Set blocking to true
|
||||||
session.set_blocking(true);
|
session.set_blocking(true);
|
||||||
match session.scp_recv(file.abs_path.as_path()) {
|
match session.scp_recv(file.abs_path.as_path()) {
|
||||||
Ok(reader) => Ok(Box::new(reader.0)),
|
Ok(reader) => Ok(Box::new(BufReader::with_capacity(8192, reader.0))),
|
||||||
Err(err) => Err(FileTransferError::new_ex(
|
Err(err) => Err(FileTransferError::new_ex(
|
||||||
FileTransferErrorType::ProtocolError,
|
FileTransferErrorType::ProtocolError,
|
||||||
format!("{}", err),
|
format!("{}", err),
|
||||||
|
|||||||
Reference in New Issue
Block a user