批处理文件未执行psftp命令

时间:2019-01-29 08:10:46

标签: tsql batch-file sftp putty psftp

我正在尝试将文件从本地系统上传到在Linux计算机中使用T-SQL cmd配置的FTP。我用要执行的命令创建了一个批处理文件,该命令在import sys import os import cv2 import numpy as np from PyQt5.QtGui import QPainter, QColor, QIcon, QPixmap, QImage from PyQt5.QtWidgets import QMainWindow, QWidget, QApplication, QAbstractButton, QLineEdit, QInputDialog, QFileDialog, QLabel, QMessageBox from PyQt5.QtCore import * #image button class PicButton(QAbstractButton): def __init__(self, pixmap, parent=None): super(PicButton, self).__init__(parent) self.pixmap = pixmap def paintEvent(self, event): painter = QPainter(self) painter.drawPixmap(event.rect(), self.pixmap) # Main Program class App(QMainWindow): clickcount = 0 def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.title = 'Recommendation System For Clothing-RSFC' self.left = 0 self.top = 0 self.width = 1350 self.height = 690 self.clickcount = 0 self.initUI() def paintEvent(self, e): qp = QPainter() qp.begin(self) self.drawRectangles(qp) qp.end() def drawRectangles(self, qp): col = QColor(0, 0, 0) col.setNamedColor('#d4d4d4') qp.setPen(col) self.rect1 = qp.setBrush(QColor(255, 255, 255)) #Outer Rectangle qp.drawRect(500, 100, 800, 570) self.rect2 = qp.setBrush(QColor(255, 255, 255)) #1st left rectangle qp.drawRect(530, 130, 330, 220) self.rect3 = qp.setBrush(QColor(255, 80, 0, 160)) #2nd left rectangle qp.drawRect(940, 130, 330, 220) self.rect4 = qp.setBrush(QColor(25, 0, 90, 200)) #1st right rectangle qp.drawRect(530, 430, 330, 220) self.rect5 = qp.setBrush(QColor(25, 0, 90, 200)) #2nd right rectangle qp.drawRect(940, 430, 330, 220) def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.setWindowIcon(QIcon('download.jpg')) # Create textbox self.textbox = QLineEdit(self) #Font for textbox font = self.textbox.font() # lineedit current font font.setPointSize(16) # change it's size self.textbox.setFont(font) # set font self.textbox.move(0, 250) self.textbox.resize(415,40) #tick and cross button for rect2 button= PicButton(QPixmap(os.path.join(os.getcwd(),"tick.svg")),self) button.move(630,350) button.resize(60,40) button.clicked.connect(self.on_click7) button= PicButton(QPixmap(os.path.join(os.getcwd(),"cross.jpg")),self) button.move(700,350) button.resize(60,40) button.clicked.connect(self.on_click8) #tick and cross button for rect3 button= PicButton(QPixmap(os.path.join(os.getcwd(),"tick.svg")),self) button.move(1040,350) button.resize(60,40) button.clicked.connect(self.on_click9) button= PicButton(QPixmap(os.path.join(os.getcwd(),"cross.jpg")),self) button.move(1110,350) button.resize(60,40) button.clicked.connect(self.on_click10) #tick and cross button for rect4 button= PicButton(QPixmap(os.path.join(os.getcwd(),"tick.svg")),self) button.move(630,650) button.resize(60,40) button.clicked.connect(self.on_click11) button= PicButton(QPixmap(os.path.join(os.getcwd(),"cross.jpg")),self) button.move(700,650) button.resize(60,40) button.clicked.connect(self.on_click12) #tick and cross button for rect5 button= PicButton(QPixmap(os.path.join(os.getcwd(),"tick.svg")),self) button.move(1040,650) button.resize(60,40) button.clicked.connect(self.on_click13) button= PicButton(QPixmap(os.path.join(os.getcwd(),"cross.jpg")),self) button.move(1110,650) button.resize(60,40) button.clicked.connect(self.on_click14) #Slogan #button= PicButton(QPixmap('C:/Users/Abhimanyu/Desktop/LYP/GUI/capture1.jpg'),self) button= PicButton(QPixmap(os.path.join(os.getcwd(),"rsfc_logo.jpg")),self) button.move(0,0) button.resize(450,225) #Search Button button = PicButton(QPixmap(os.path.join(os.getcwd(),"search.jpg")),self) button.setToolTip('Start personalized search') button.move(420,250) button.resize(30,40) button.clicked.connect(self.search) #Face Detect Button button = PicButton(QPixmap(os.path.join(os.getcwd(),"face_detect.jpg")),self) button.setToolTip('Click and detect') button.move(15,320) button.resize(175,80) button.clicked.connect(self.face_detect) #Upload Button button = PicButton(QPixmap(os.path.join(os.getcwd(),"upload.jpg")),self) button.setToolTip('Upload clothing pic') button.move(275,320) button.resize(175,80) button.clicked.connect(self.upload) #Select Button button = PicButton(QPixmap(os.path.join(os.getcwd(),"select.jpg")),self) button.setToolTip('Select clothing image') button.move(15,580) button.resize(175,80) button.clicked.connect(self.select) #webcam button button = PicButton(QPixmap(os.path.join(os.getcwd(),"webcam.jpg")),self) button.setToolTip('webcam detect') button.move(100,430) button.resize(250,120) button.clicked.connect(self.webcam) #Match clothes button button = PicButton(QPixmap(os.path.join(os.getcwd(),"match.jpg")),self) button.setToolTip('Match clothes') button.move(275,580) button.resize(175,80) button.clicked.connect(self.match) #Searchbox on click def search(self): textboxValue = self.textbox.text() print(textboxValue) textboxValue = self.textbox.setText("") #Webcam onclick def webcam(self): print('webcam detect') filename, okPressed = QInputDialog.getText(self, "Get text","Your name:", QLineEdit.Normal, "") if okPressed and filename != '': cam = cv2.VideoCapture(0) s, img = cam.read() #cv2.imshow("Test",im) cv2.imwrite(filename+".jpg", img) os.system("python -m label_image_gender --graph=retrained_graph_gender.pb --image="+filename+".jpg") os.system("python -m label_image_beard_shaved --graph=retrained_graph_beard_shaved.pb --image="+filename+".jpg") os.system("python -m label_image_tone --graph=retrained_graph_tone.pb --image="+filename+".jpg") elif okPressed and filename == "": QMessageBox.about(self, 'Error', 'Please enter your name!') self.webcam() #Detect face onclick def face_detect(self): print('face detect') #Select pic to detect face window = QWidget() filename,_filter = QFileDialog.getOpenFileName(window, 'Open Image', '/', 'Image Files (*.png *.xpm *.jpg *.bmp)') #face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') #img = cv2.imread(filename) print("Started") os.system("python -m label_image_gender --graph=retrained_graph_gender.pb --image="+filename) os.system("python -m label_image_beard_shaved --graph=retrained_graph_beard_shaved.pb --image="+filename) os.system("python -m label_image_tone --graph=retrained_graph_tone.pb --image="+filename) #Upload file onclick def upload(self, value=""): self.clickcount += 1 if self.clickcount == 5: QMessageBox.about(self, 'Error', 'You cant Upload 5 image') else: window = QWidget() filename,_filter = QFileDialog.getOpenFileName(window, 'Open Image', '/', 'Image Files (*.png *.xpm *.jpg *.bmp)') print(filename) if self.clickcount == 1: button1 = PicButton(QPixmap(filename),self) #Image displaying button1.setToolTip('First Pic Uploaded') button1.move(530,130) button1.resize(330,220) button1.show() elif self.clickcount == 2: button2 = PicButton(QPixmap(filename),self) #Image displaying button2.setToolTip('Second Pic Uploaded') button2.move(940,130) button2.resize(330,220) button2.show() elif self.clickcount == 3: button3 = PicButton(QPixmap(filename),self) #Image displaying button3.setToolTip('Second Pic Uploaded') button3.move(530,430) button3.resize(330,220) button3.show() elif self.clickcount == 4: button4 = PicButton(QPixmap(filename),self) #Image displaying button4.setToolTip('Fourth Pic Uploaded') button4.move(940,430) button4.resize(330,220) button4.show() #Select on click def select(self): print('select') #Match clothes onclick def match(self): print('matching') # tick for rect2 def on_click7(self): print('i loved the cloth') # cross for rect2 def on_click8(self): #QtCore.QObject.connect(self.deletebutton1, QtCore.SIGNAL("clicked()"), button1.clear) self.upload("rect2") self.clickcount -= 1 # tick for rect3 def on_click9(self): print('i loved the cloth') # cross for rect3 def on_click10(self): print('i hate this type of cloth') # tick for rect4 def on_click11(self): print('i loved the cloth') # cross for rect4 def on_click12(self): print('i hate this type of cloth') # tick for rect5 def on_click13(self): print('i loved the cloth') # cross for rect5 def on_click14(self): print('i hate this type of cloth') if __name__ == '__main__': APP = QApplication(sys.argv) ex = App() ex.show() sys.exit(APP.exec_()) 中正常工作,而在使用xp_CMDShell在SQL中调用同一批处理文件时,该文件在T-SQL中不工作。请在下面找到我使用的命令。

批处理文件cmd:

cmd

T-SQL:

cd C:\Program Files\PuTTY
psftp.exe
open FTPip
username
password
put D:\localpath\filename /home/destinationpath/filename
quit 

T-SQL响应:

  

C:\ Windows \ system32> cd C:\ Program Files \ PuTTY NULL C:\ Program   Files \ PuTTY> psftp.exe psftp:未指定主机名;使用“打开   host.name”以连接psftp>退出NULL C:\ Program Files \ PuTTY> open   ftpip'open'无法识别为内部或外部命令,   可操作的程序或批处理文件。 NULL C:\ Program Files \ PuTTY>用户名   无法将“用户名”识别为内部或外部命令,   可操作的程序或批处理文件。 NULL C:\ Program Files \ PuTTY>密码   无法将“密码”识别为内部或外部命令,   可操作的程序或批处理文件。 NULL C:\ Program Files \ PuTTY>退出
  'quit'不被识别为内部或外部命令,可操作   程序或批处理文件。 NULL

请让我知道我想念的地方。

1 个答案:

答案 0 :(得分:0)

您正在将psftp命令和Windows命令组合到一个文件中。那行不通。批处理文件在对psftp的调用上停止,并等待其完成。相反,psftp不知道该批处理文件甚至存在,因此无法从那里读取其命令。

psftp命令(openquit行)放入单独的文件(upload.txt)中,并使用以下命令执行:

"C:\Program Files\PuTTY\psftp.exe -b c:\path\to\upload.txt

(您可以直接从T-SQL执行该命令或将其放入批处理文件中)


请注意,您的批处理文件也无法从cmd开始工作,这与您在问题中提出的要求相反。您可能是说,手动在cmd中输入这些行是有用的。