MCPcopy Create free account
hub / github.com/VirusTotal/vt-cli / Do

Method Do

cmd/scan.go:83–132  ·  view source on GitHub ↗
(path interface{}, ds *utils.DoerState)

Source from the content-addressed store, hash-verified

81}
82
83func (s *fileScanner) Do(path interface{}, ds *utils.DoerState) string {
84
85 progressCh := make(chan float32)
86 defer close(progressCh)
87
88 go func() {
89 for progress := range progressCh {
90 if progress < 100 {
91 ds.Progress = fmt.Sprintf("%s uploading... %4.1f%%", path, progress)
92 } else {
93 ds.Progress = fmt.Sprintf("%s scanning...", path)
94 }
95 }
96 }()
97
98 f, err := os.Open(path.(string))
99 if err != nil {
100 return err.Error()
101 }
102 defer f.Close()
103
104 var analysis *vt.Object
105 if s.password != "" {
106 analysis, err = s.scanner.ScanFileWithParameters(
107 f, progressCh, map[string]string{"password": s.password})
108 } else {
109 analysis, err = s.scanner.ScanFile(f, progressCh)
110 }
111 if err != nil {
112 return err.Error()
113 }
114
115 if s.showInVT {
116 // Return the analysis URL in VT so users can visit it.
117 return fmt.Sprintf(
118 "%s https://www.virustotal.com/gui/file-analysis/%s",
119 path.(string), analysis.ID())
120 }
121
122 if s.waitForCompletion {
123 analysisResult, err := waitForAnalysisResults(s.cli, analysis.ID(), ds)
124 if err != nil {
125 return err.Error()
126 }
127 s.printer.PrintObject(analysisResult)
128 return ""
129 }
130
131 return fmt.Sprintf("%s %s", path.(string), analysis.ID())
132}
133
134var scanFileCmdHelp = `Scan one or more files.
135

Callers

nothing calls this directly

Calls 2

waitForAnalysisResultsFunction · 0.85
PrintObjectMethod · 0.80

Tested by

no test coverage detected